From 25d7787d9fbe4f70d9bf7bcd1bc30748b51fe1ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20Sundstr=C3=B6m?= Date: Fri, 19 Jan 2024 21:39:45 +0100 Subject: [PATCH] IOS7: Add functions creating UIKeyCommands for Fn keys Use the helper function to create an array of UIKeyCommands for the Fn keys. Add a generic handler function that decides which action for which key. This allows the application to register key presses of the Fn keys, however only supoorted in iOS 13.4 and later. --- backends/platform/ios7/ios7_keyboard.mm | 37 +++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/backends/platform/ios7/ios7_keyboard.mm b/backends/platform/ios7/ios7_keyboard.mm index 4e2b45d7b14..f39cfa9f4f3 100644 --- a/backends/platform/ios7/ios7_keyboard.mm +++ b/backends/platform/ios7/ios7_keyboard.mm @@ -320,6 +320,14 @@ return [self overloadKeys:numArray withSelector:@selector(handleNumberKey:)]; } +- (NSArray *)overloadFnKeys { + if (@available(iOS 13.4, *)) { + NSArray *fnKeys = [[NSArray alloc] initWithObjects:UIKeyInputF1, UIKeyInputF2, UIKeyInputF3, UIKeyInputF4, UIKeyInputF5, UIKeyInputF6, UIKeyInputF7, UIKeyInputF8, UIKeyInputF9, UIKeyInputF10, UIKeyInputF11, UIKeyInputF12, nil]; + return [self overloadKeys:fnKeys withSelector:@selector(handleFnKey:)]; + } + return nil; +} + - (int)convertModifierFlags:(UIKeyModifierFlags)flags { return (((flags & UIKeyModifierShift) ? Common::KBD_SHIFT : 0) | ((flags & UIKeyModifierControl) ? Common::KBD_CTRL : 0) | @@ -403,6 +411,35 @@ } } +- (void)handleFnKey:(UIKeyCommand *)keyCommand { + if (@available(iOS 13.4, *)) { + if (keyCommand.input == UIKeyInputF1) { + [self fn1Key]; + } else if (keyCommand.input == UIKeyInputF2) { + [self fn2Key]; + } else if (keyCommand.input == UIKeyInputF3) { + [self fn3Key]; + } else if (keyCommand.input == UIKeyInputF4) { + [self fn4Key]; + } else if (keyCommand.input == UIKeyInputF5) { + [self fn5Key]; + } else if (keyCommand.input == UIKeyInputF6) { + [self fn6Key]; + } else if (keyCommand.input == UIKeyInputF7) { + [self fn7Key]; + } else if (keyCommand.input == UIKeyInputF8) { + [self fn8Key]; + } else if (keyCommand.input == UIKeyInputF9) { + [self fn9Key]; + } else if (keyCommand.input == UIKeyInputF10) { + [self fn10Key]; + } else if (keyCommand.input == UIKeyInputF11) { + [self fn11Key]; + } else if (keyCommand.input == UIKeyInputF12) { + [self fn12Key]; + } + } +} - (NSArray *)keyCommands { UIKeyCommand *upArrow = [UIKeyCommand keyCommandWithInput: UIKeyInputUpArrow modifierFlags: 0 action: @selector(upArrow:)];