kasper / phoenix

A lightweight macOS window and app manager scriptable with JavaScript
https://kasper.github.io/phoenix/
Other
4.36k stars 128 forks source link

ctrl-1 key binding not working #218

Closed rdinse closed 6 years ago

rdinse commented 6 years ago
var setupHandlers = function() {
    return {
        ctrl1: new Key('1', ['ctrl'], function() { Phoenix.log("Key 1") }),
        ctrl2: new Key('2', ['ctrl'], function() { Phoenix.log("Key 2") }),
    };
}

var keyHandlers = setupHandlers();

On my machine, the code above works for crtl-2, but not in case of ctrl-1.

kasper commented 6 years ago

@rdinse Hi! Check the logs from the Console app. I presume it has been registered by the system or by some other app.

rdinse commented 6 years ago

I've disabled USB Overdrive and Karabiner-Elements (the only programs with global keyboard bindings that I am aware of) and I checked all shortcuts in the system's keyboard settings. It still does not work. The curious thing is also that ctrl-1 appears to be passed through completely normally, at least according to Emacs (it captures it as C-u 1- as expected) and Karabiner's event viewer (key_down 0xe0 left_control, key_down 0x1e 1, key_up 0xe0 left_control, key_up key_down 0x1e 1). So it does not seem to be registered by any app.

kasper commented 6 years ago

@rdinse Looks like the system registers ctrl + 1...n for switching between Spaces. By default you only have one space. You can disable this under the Keyboard shortcut preferences in System Preferences.

Key.on('1', [ 'ctrl' ], () => Phoenix.log('ctrl + 1'));
Key.on('2', [ 'ctrl' ], () => Phoenix.log('ctrl + 2'));

If you check the logs, Phoenix emits an error when trying to bind ctrl + 1. The error code -9878 represents the case where the hot key already exists and cannot be bound again.

2018-06-13 21:53:10.956886+0300 Phoenix[3567:289265] Error: Could not register key 18 (0) with modifiers 4096. (-9878)
2018-06-13 21:53:10.958290+0300 Phoenix[3567:289265] Context loaded.
2018-06-13 21:53:24.697384+0300 Phoenix[3567:289265] ctrl + 2
rdinse commented 6 years ago

Interesting, thanks, but it does not work. I am getting the same message:

default 23:15:10.442205 +0200   Phoenix Error: Could not register key 18 (95) with modifiers 4096. (-9878)

The ^1 shortcut in Settings > Mission Control > Mission Control > Switch to Desktop 1 was already disabled. Enabling & re-disabling it did not help. Does it work on your machine?

kasper commented 6 years ago

Ah, right. It seems if you disable the setting, other system apps register the same shortcut for other purposes. I suggest you use additional modifiers in this case.

rdinse commented 6 years ago

This seems to be a bug in macOS: https://apple.stackexchange.com/questions/135814

I found a workaround by binding the Spaces to shift+^[number] and then disabling them. ¯\_(ツ)_/¯

Thanks anyway.

kasper commented 6 years ago

Haha, glad you got it sorted out!