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.
This commit is contained in:
Lars Sundström committed 2024-02-23 22:41:18 +01:00
1 parent 25d7787d9f
commit c5ef6ecb77
1 file changed
+27
+27
View File
@@ -328,6 +328,16 @@
return nil;
}
- (NSArray *)overloadSpecialKeys {
NSMutableArray<NSString *> *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];