diff options
| author | Hannes Schulze <haschu0103@outlook.de> | 2025-01-29 00:58:07 +0100 |
|---|---|---|
| committer | Hannes Schulze <haschu0103@outlook.de> | 2025-01-29 00:58:07 +0100 |
| commit | c1062208bb54cce8dffa04e9697ae124f271ecaf (patch) | |
| tree | 5d387dcb76ec26a87d7ecafb983939b359c8f11e /app/mac/controller-adapter-keyboard.mm | |
| parent | 117f584b3f3d7945732a29848eb6d4ead1f57bee (diff) | |
use game controller api for input
Diffstat (limited to 'app/mac/controller-adapter-keyboard.mm')
| -rw-r--r-- | app/mac/controller-adapter-keyboard.mm | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/app/mac/controller-adapter-keyboard.mm b/app/mac/controller-adapter-keyboard.mm new file mode 100644 index 0000000..ad3dda8 --- /dev/null +++ b/app/mac/controller-adapter-keyboard.mm @@ -0,0 +1,44 @@ +#import "controller-adapter-keyboard.hh" + +@implementation ControllerAdapterKeyboard + +- (instancetype)init +{ + self = [super init]; + if (self) + { + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(handleKeyboardConnected:) + name:GCKeyboardDidConnectNotification + object:nil]; + } + return self; +} + +- (void)dealloc +{ + [[NSNotificationCenter defaultCenter] removeObserver:self]; +} + +- (void)handleKeyboardConnected:(NSNotification*)notification +{ + _keyboard = [GCKeyboard coalescedKeyboard]; +} + +- (nes::button_mask)readPressedButtons +{ + auto profile = [[self keyboard] keyboardInput]; + + auto res = nes::button_mask{}; + if ([[profile buttonForKeyCode:GCKeyCodeUpArrow] isPressed]) { res.add(nes::buttons::up); } + if ([[profile buttonForKeyCode:GCKeyCodeDownArrow] isPressed]) { res.add(nes::buttons::down); } + if ([[profile buttonForKeyCode:GCKeyCodeLeftArrow] isPressed]) { res.add(nes::buttons::left); } + if ([[profile buttonForKeyCode:GCKeyCodeRightArrow] isPressed]) { res.add(nes::buttons::right); } + if ([[profile buttonForKeyCode:GCKeyCodeKeyZ] isPressed]) { res.add(nes::buttons::a); } + if ([[profile buttonForKeyCode:GCKeyCodeKeyX] isPressed]) { res.add(nes::buttons::b); } + if ([[profile buttonForKeyCode:GCKeyCodeReturnOrEnter] isPressed]) { res.add(nes::buttons::start); } + if ([[profile buttonForKeyCode:GCKeyCodeSpacebar] isPressed]) { res.add(nes::buttons::select); } + return res; +} + +@end
\ No newline at end of file |
