From 66199059024dc014a658d8fcc83f4c432a74b06f Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Wed, 5 Jun 2013 21:39:59 +0200 Subject: [PATCH] macosx_events: DRY up key lookup over dictionary Two methods duplicated very similar behaviour. Extract method with the common behaviour. --- osdep/macosx_events.m | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/osdep/macosx_events.m b/osdep/macosx_events.m index 661ef638ca..aff83a866f 100644 --- a/osdep/macosx_events.m +++ b/osdep/macosx_events.m @@ -232,13 +232,7 @@ void cocoa_put_key(int keycode) @(NX_KEYTYPE_FAST): @(MP_MK_NEXT), }; - int mpkey = [keymap[@(key)] intValue]; - if (mpkey > 0) { - cocoa_put_key(mpkey); - return YES; - } else { - return NO; - } + return [self handleKey:key withMapping:keymap]; } - (NSEvent*)handleKeyDown:(NSEvent *)event { @@ -296,8 +290,16 @@ void cocoa_put_key(int keycode) @(kHIDRemoteButtonCodeDownHold): @(MP_AR_VDOWN_HOLD), }; - int key = [keymap[@(buttonCode)] intValue]; - if (key > 0) - cocoa_put_key(key); + [self handleKey:buttonCode withMapping:keymap]; +} +-(BOOL)handleKey:(int)key withMapping:(NSDictionary *)mapping +{ + int mpkey = [mapping[@(key)] intValue]; + if (mpkey > 0) { + cocoa_put_key(mpkey); + return YES; + } else { + return NO; + } } @end