From c5ef6ecb77561fb607d4a7cea01acc3fab61ba3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20Sundstr=C3=B6m?= Date: Sat, 20 Jan 2024 21:17:48 +0100 Subject: [PATCH] IOS7: Add functions creating UIKeyCommands for special keys Use the helper function to create an array of UIKeyCommands for the END, HOME, PAGE UP, PAGE DOWN and the ESC keys. Add a generic handler function that decides which action for which key. This allows the application to register key presses of these keys, however some of them requires iOS 13.4 or later. --- backends/platform/ios7/ios7_keyboard.mm | 27 +++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/backends/platform/ios7/ios7_keyboard.mm b/backends/platform/ios7/ios7_keyboard.mm index f39cfa9f4f3..ab095968df5 100644 --- a/backends/platform/ios7/ios7_keyboard.mm +++ b/backends/platform/ios7/ios7_keyboard.mm @@ -328,6 +328,16 @@ return nil; } +- (NSArray *)overloadSpecialKeys { + NSMutableArray *specialKeys = [[NSMutableArray alloc] initWithObjects:UIKeyInputEscape, UIKeyInputPageUp, UIKeyInputPageDown, nil]; + + if (@available(iOS 13.4, *)) { + [specialKeys addObject: UIKeyInputHome]; + [specialKeys addObject: UIKeyInputEnd]; + } + return [self overloadKeys:specialKeys withSelector:@selector(handleSpecialKey:)]; +} + - (int)convertModifierFlags:(UIKeyModifierFlags)flags { return (((flags & UIKeyModifierShift) ? Common::KBD_SHIFT : 0) | ((flags & UIKeyModifierControl) ? Common::KBD_CTRL : 0) | @@ -441,6 +451,23 @@ } } +- (void)handleSpecialKey:(UIKeyCommand *)keyCommand { + if (keyCommand.input == UIKeyInputEscape) { + [self escapeKey:keyCommand]; + } else if (keyCommand.input == UIKeyInputPageUp) { + [softKeyboard handleKeyPress:Common::KEYCODE_PAGEUP withModifierFlags:[self convertModifierFlags:keyCommand.modifierFlags]]; + } else if (keyCommand.input == UIKeyInputPageDown) { + [softKeyboard handleKeyPress:Common::KEYCODE_PAGEDOWN withModifierFlags:[self convertModifierFlags:keyCommand.modifierFlags]]; + } + if (@available(iOS 13.4, *)) { + if (keyCommand.input == UIKeyInputHome) { + [softKeyboard handleKeyPress:Common::KEYCODE_HOME withModifierFlags:[self convertModifierFlags:keyCommand.modifierFlags]]; + } else if (keyCommand.input == UIKeyInputEnd) { + [softKeyboard handleKeyPress:Common::KEYCODE_END withModifierFlags:[self convertModifierFlags:keyCommand.modifierFlags]]; + } + } +} + - (NSArray *)keyCommands { UIKeyCommand *upArrow = [UIKeyCommand keyCommandWithInput: UIKeyInputUpArrow modifierFlags: 0 action: @selector(upArrow:)]; [self setWantsPriority: upArrow];