From a42a10eb86de2ff3784f3cfb56410eff927569b5 Mon Sep 17 00:00:00 2001 From: Aaron Culliney Date: Sun, 12 Oct 2014 16:44:49 -0700 Subject: [PATCH] Beginnings of key handling for Apple2Mac --- .../Classes/OSX/EmulatorWindowController.m | 46 ++++++++++++++----- src/keys.c | 4 +- 2 files changed, 36 insertions(+), 14 deletions(-) diff --git a/Apple2Mac/Apple2Mac/Classes/OSX/EmulatorWindowController.m b/Apple2Mac/Apple2Mac/Classes/OSX/EmulatorWindowController.m index a5f6956d..d7e1bc70 100644 --- a/Apple2Mac/Apple2Mac/Classes/OSX/EmulatorWindowController.m +++ b/Apple2Mac/Apple2Mac/Classes/OSX/EmulatorWindowController.m @@ -18,6 +18,8 @@ #define NIB_PROPERTIES @".nib 232960 bytes" #define GZ_EXTENSION @"gz" +#define KEYCODE_CAPS_LOCK 0x39 + @interface EmulatorWindowController () @property (nonatomic, assign) IBOutlet EmulatorGLView *view; @@ -312,22 +314,42 @@ self.fullscreenWindow = nil; } +- (void)flagsChanged:(NSEvent*)event +{ + static BOOL modified_caps_lock = NO; + if ([event keyCode] == KEYCODE_CAPS_LOCK) + { + NSUInteger flags = [event modifierFlags]; + if (flags & NSAlphaShiftKeyMask) + { + modified_caps_lock = YES; + caps_lock = true; + } + else + { + caps_lock = false; + } + } +} + +- (void)keyUp:(NSEvent *)event +{ + unichar c = [[event charactersIgnoringModifiers] characterAtIndex:0]; + + c_keys_handle_input((int)c, 0, 1); + + // Allow other character to be handled (or not and beep) + //[super keyDown:event]; +} + - (void)keyDown:(NSEvent *)event { - unichar c = [[event charactersIgnoringModifiers] characterAtIndex:0]; + unichar c = [[event charactersIgnoringModifiers] characterAtIndex:0]; - switch (c) - { - case 27: - NSLog(@"key ESC"); - return; - case 'f': - NSLog(@"key 'f'"); - return; - } + c_keys_handle_input((int)c, 1, 1); - // Allow other character to be handled (or not and beep) - [super keyDown:event]; + // Allow other character to be handled (or not and beep) + //[super keyDown:event]; } @end diff --git a/src/keys.c b/src/keys.c index 34fdcb59..178100e0 100644 --- a/src/keys.c +++ b/src/keys.c @@ -32,7 +32,7 @@ extern int raw_js_y; static int next_key = -1; static int last_scancode = -1; -bool caps_lock = false; /* is enabled */ +bool caps_lock = true; // default enabled because so much breaks otherwise /* ---------------------------------------------------- //e Keymap. Mapping scancodes to Apple //e US Keyboard @@ -171,7 +171,6 @@ void c_keys_handle_input(int scancode, int pressed, int is_cooked) { int *keymap = NULL; - assert(scancode < 0x80); if (is_cooked) { last_scancode = -1; if (!pressed) { @@ -184,6 +183,7 @@ void c_keys_handle_input(int scancode, int pressed, int is_cooked) } next_key = scancode; } else if (scancode >= 0) { + assert(scancode < 0x80); last_scancode = scancode; if ((key_pressed[ SCODE_L_SHIFT ] || key_pressed[ SCODE_R_SHIFT ]) &&