diff --git a/OSBindings/Mac/Clock Signal/Documents/MachineDocument.swift b/OSBindings/Mac/Clock Signal/Documents/MachineDocument.swift index e517113e5..14bc46168 100644 --- a/OSBindings/Mac/Clock Signal/Documents/MachineDocument.swift +++ b/OSBindings/Mac/Clock Signal/Documents/MachineDocument.swift @@ -532,7 +532,7 @@ class MachineDocument: // MARK: Joystick-via-the-keyboard selection @IBAction func useKeyboardAsKeyboard(_ sender: NSMenuItem?) { - machine.inputMode = .keyboard + machine.inputMode = .keyboardPhysical } @IBAction func useKeyboardAsJoystick(_ sender: NSMenuItem?) { @@ -551,7 +551,7 @@ class MachineDocument: return false } - menuItem.state = machine.inputMode == .keyboard ? .on : .off + menuItem.state = machine.inputMode == .keyboardPhysical ? .on : .off return true case #selector(self.useKeyboardAsJoystick): diff --git a/OSBindings/Mac/Clock Signal/Machine/CSMachine.h b/OSBindings/Mac/Clock Signal/Machine/CSMachine.h index d4830b7f5..a437e5f4d 100644 --- a/OSBindings/Mac/Clock Signal/Machine/CSMachine.h +++ b/OSBindings/Mac/Clock Signal/Machine/CSMachine.h @@ -28,8 +28,9 @@ typedef NS_ENUM(NSInteger, CSMachineVideoSignal) { }; typedef NS_ENUM(NSInteger, CSMachineKeyboardInputMode) { - CSMachineKeyboardInputModeKeyboard, - CSMachineKeyboardInputModeJoystick + CSMachineKeyboardInputModeKeyboardPhysical, + CSMachineKeyboardInputModeKeyboardLogical, + CSMachineKeyboardInputModeJoystick, }; @interface CSMissingROM: NSObject diff --git a/OSBindings/Mac/Clock Signal/Machine/CSMachine.mm b/OSBindings/Mac/Clock Signal/Machine/CSMachine.mm index a671a87b7..4a125c679 100644 --- a/OSBindings/Mac/Clock Signal/Machine/CSMachine.mm +++ b/OSBindings/Mac/Clock Signal/Machine/CSMachine.mm @@ -201,9 +201,10 @@ struct ActivityObserver: public Activity::Observer { return nil; } + // Use the keyboard as a joystick if the machine has no keyboard, or if it has a 'non-exclusive' keyboard. _inputMode = (_machine->keyboard_machine() && _machine->keyboard_machine()->get_keyboard().is_exclusive()) - ? CSMachineKeyboardInputModeKeyboard : CSMachineKeyboardInputModeJoystick; + ? CSMachineKeyboardInputModeKeyboardPhysical : CSMachineKeyboardInputModeJoystick; _leds = [[NSMutableArray alloc] init]; Activity::Source *const activity_source = _machine->activity_source(); @@ -429,7 +430,7 @@ struct ActivityObserver: public Activity::Observer { - (void)setKey:(uint16_t)key characters:(NSString *)characters isPressed:(BOOL)isPressed { auto keyboard_machine = _machine->keyboard_machine(); - if(keyboard_machine && (self.inputMode == CSMachineKeyboardInputModeKeyboard || !keyboard_machine->get_keyboard().is_exclusive())) { + if(keyboard_machine && (self.inputMode != CSMachineKeyboardInputModeJoystick || !keyboard_machine->get_keyboard().is_exclusive())) { Inputs::Keyboard::Key mapped_key = Inputs::Keyboard::Key::Help; // Make an innocuous default guess. #define BIND(source, dest) case source: mapped_key = Inputs::Keyboard::Key::dest; break; // Connect the Carbon-era Mac keyboard scancodes to Clock Signal's 'universal' enumeration in order @@ -503,9 +504,19 @@ struct ActivityObserver: public Activity::Observer { } } - @synchronized(self) { - keyboard.set_key_pressed(mapped_key, pressedKey, isPressed); + if(self.inputMode == CSMachineKeyboardInputModeKeyboardLogical) { + if(isPressed) { + @synchronized(self) { + char string[2] = { pressedKey, 0 }; + keyboard_machine->type_string(string); + } + } + } else { + @synchronized(self) { + keyboard.set_key_pressed(mapped_key, pressedKey, isPressed); + } } + return; } }