Skip to content

Instantly share code, notes, and snippets.

@ferbass
Last active March 9, 2020 12:55
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ferbass/0ddea86e6b2eb5915fabdbfe9f151a5e to your computer and use it in GitHub Desktop.
Save ferbass/0ddea86e6b2eb5915fabdbfe9f151a5e to your computer and use it in GitHub Desktop.
NSMutableArray *commands = [[NSMutableArray alloc] init];
NSString *characters = @"`1234567890-=qwertyuiop[]asdfghjkl;'zxcvbnm,./";
for (NSInteger i = 0; i < characters.length; i++) {
NSString *input = [characters substringWithRange:NSMakeRange(i, 1)];
/* Caps Lock */
[commands addObject:[UIKeyCommand keyCommandWithInput:input modifierFlags:UIKeyModifierAlphaShift action:@selector(handleCommand:)]];
/* Shift */
[commands addObject:[UIKeyCommand keyCommandWithInput:input modifierFlags:UIKeyModifierShift action:@selector(handleCommand:)]];
/* Control */
[commands addObject:[UIKeyCommand keyCommandWithInput:input modifierFlags:UIKeyModifierControl action:@selector(handleCommand:)]];
/* Option */
[commands addObject:[UIKeyCommand keyCommandWithInput:input modifierFlags:UIKeyModifierAlternate action:@selector(handleCommand:)]];
/* Command */
[commands addObject:[UIKeyCommand keyCommandWithInput:input modifierFlags:UIKeyModifierCommand action:@selector(handleCommand:)]];
/* Control + Option */
[commands addObject:[UIKeyCommand keyCommandWithInput:input modifierFlags:UIKeyModifierControl | UIKeyModifierAlternate action:@selector(handleCommand:)]];
/* Control + Command */
[commands addObject:[UIKeyCommand keyCommandWithInput:input modifierFlags:UIKeyModifierControl | UIKeyModifierCommand action:@selector(handleCommand:)]];
/* Option + Command */
[commands addObject:[UIKeyCommand keyCommandWithInput:input modifierFlags:UIKeyModifierAlternate | UIKeyModifierCommand action:@selector(handleCommand:)]];
/* Control + Option + Command */
[commands addObject:[UIKeyCommand keyCommandWithInput:input modifierFlags:UIKeyModifierControl | UIKeyModifierAlternate | UIKeyModifierCommand action:@selector(handleCommand:)]];
/* No modifier */
[commands addObject:[UIKeyCommand keyCommandWithInput:input modifierFlags:kNilOptions action:@selector(handleCommand:)]];
}
/* Delete */
[commands addObject:[UIKeyCommand keyCommandWithInput:@"\b" modifierFlags:kNilOptions action:@selector(handleCommand:)]];
/* Tab */
[commands addObject:[UIKeyCommand keyCommandWithInput:@"\t" modifierFlags:kNilOptions action:@selector(handleCommand:)]];
/* Enter */
[commands addObject:[UIKeyCommand keyCommandWithInput:@"\r" modifierFlags:kNilOptions action:@selector(handleCommand:)]];
/* Up */
[commands addObject:[UIKeyCommand keyCommandWithInput:UIKeyInputUpArrow modifierFlags:kNilOptions action:@selector(handleCommand:)]];
/* Down */
[commands addObject:[UIKeyCommand keyCommandWithInput:UIKeyInputDownArrow modifierFlags:kNilOptions action:@selector(handleCommand:)]];
/* Left */
[commands addObject:[UIKeyCommand keyCommandWithInput:UIKeyInputLeftArrow modifierFlags:kNilOptions action:@selector(handleCommand:)]];
/* Right */
[commands addObject:[UIKeyCommand keyCommandWithInput:UIKeyInputRightArrow modifierFlags:kNilOptions action:@selector(handleCommand:)]];
/* Esc */
[commands addObject:[UIKeyCommand keyCommandWithInput:UIKeyInputEscape modifierFlags:kNilOptions action:@selector(handleCommand:)]];
@ferbass
Copy link
Author

ferbass commented Jun 28, 2016

sample in Objective-c, if you need to use it with swift follow the sample bellow
/* Enter */
UIKeyCommand.init(input: "\r", modifierFlags: [], action: nil)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment