1. There is a field of characters

. . . . . . @. . . . . . . 
  1. By pressing the keyboard key on a Mac, you need to move the @ symbol
  2. Everything happens in the Xcode console

How to respond to keyboard events?

  • “Everything happens in the Xcode console” - uh, will the program be delivered to the client along with Xcode? - VladD
  • It will not be delivered anywhere! This is just a challenge! - Artem

1 answer 1

Any class that inherits from NSResponder responds to keyDown or keyUp

 - (void)keyDown:(NSEvent *)theEvent { NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter]; unsigned short keyCode = [theEvent keyCode]; if([theEvent modifierFlags] & NSCommandKeyMask && keyCode == 36 /*Cmd+Enter*/) { [notificationCenter postNotificationName:@"cmdEnterKeyPressedNotification" object:nil]; return; } if(keyCode == 36 /*Enter*/) { [notificationCenter postNotificationName:@"enterKeyPressedNotification" object:nil]; return; } if(keyCode == 49 /*Space*/) { [notificationCenter postNotificationName:@"spaceKeyPressedNotification" object:nil]; return; } [super keyDown:theEvent]; 

}