joshgoebel / keyszer

a smart, flexible keymapper for X11 (a fork/reboot of xkeysnail )
Other
69 stars 15 forks source link

Default config freezes when `{Key.CAPSLOCK: [Key.ESC, Key.LEFT_CTRL]}` enabled #121

Open zenny opened 1 year ago

zenny commented 1 year ago

Hi,

I used the default configuration with following minor change to switch capslock:

multipurpose_modmap("default",
    # Enter is enter when pressed and released. Control when held down.
    {Key.ENTER: [Key.ENTER, Key.RIGHT_CTRL]},

    # Capslock is escape when pressed and released. Control when held down.
    {Key.CAPSLOCK: [Key.ESC, Key.LEFT_CTRL]}
    # To use this example, you can't remap capslock with modmap.
)

xcape and xmodmap was disabled, but pressing default (qwerty) ENTER is unresponsive and produces the following :

keyszer --devices /dev/input/event8 "SEMICO USB Keyboard"
keyszer v0.6.92
(+K) Grabbing SEMICO USB Keyboard (/dev/input/event4)
(+K) Grabbing SEMICO USB Keyboard (/dev/input/event8)
(--) Ready to process input.
Exception in callback receive_input(InputDevice('...input/event4')) at /home/zenny/.local/lib/python3.11/site-packages/keyszer/input.py:102
handle: <Handle receive_input(InputDevice('...input/event4')) at /home/zenny/.local/lib/python3.11/site-packages/keyszer/input.py:102>
Traceback (most recent call last):
  File "/usr/lib/python3.11/asyncio/events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "/home/zenny/.local/lib/python3.11/site-packages/keyszer/input.py", line 117, in receive_input
    on_event(event, device)
  File "/home/zenny/.local/lib/python3.11/site-packages/keyszer/transform.py", line 329, in on_event
    apply_multi_modmap(ks, context)
  File "/home/zenny/.local/lib/python3.11/site-packages/keyszer/transform.py", line 253, in apply_multi_modmap
    if modmap.conditional(context):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: 'dict' object is not callable
Exception in callback receive_input(InputDevice('...input/event4')) at /home/zenny/.local/lib/python3.11/site-packages/keyszer/input.py:102
handle: <Handle receive_input(InputDevice('...input/event4')) at /home/zenny/.local/lib/python3.11/site-packages/keyszer/input.py:102>
Traceback (most recent call last):
  File "/usr/lib/python3.11/asyncio/events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "/home/zenny/.local/lib/python3.11/site-packages/keyszer/input.py", line 117, in receive_input
    on_event(event, device)
  File "/home/zenny/.local/lib/python3.11/site-packages/keyszer/transform.py", line 329, in on_event
    apply_multi_modmap(ks, context)
  File "/home/zenny/.local/lib/python3.11/site-packages/keyszer/transform.py", line 253, in apply_multi_modmap
    if modmap.conditional(context):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: 'dict' object is not callable
Exception in callback receive_input(InputDevice('...input/event4')) at /home/zenny/.local/lib/python3.11/site-packages/keyszer/input.py:102
handle: <Handle receive_input(InputDevice('...input/event4')) at /home/zenny/.local/lib/python3.11/site-packages/keyszer/input.py:102>
Traceback (most recent call last):
  File "/usr/lib/python3.11/asyncio/events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "/home/zenny/.local/lib/python3.11/site-packages/keyszer/input.py", line 117, in receive_input
    on_event(event, device)
  File "/home/zenny/.local/lib/python3.11/site-packages/keyszer/transform.py", line 329, in on_event
    apply_multi_modmap(ks, context)
  File "/home/zenny/.local/lib/python3.11/site-packages/keyszer/transform.py", line 253, in apply_multi_modmap
    if modmap.conditional(context):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: 'dict' object is not callable
Exception in callback receive_input(InputDevice('...input/event4')) at /home/zenny/.local/lib/python3.11/site-packages/keyszer/input.py:102
handle: <Handle receive_input(InputDevice('...input/event4')) at /home/zenny/.local/lib/python3.11/site-packages/keyszer/input.py:102>
Traceback (most recent call last):
  File "/usr/lib/python3.11/asyncio/events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "/home/zenny/.local/lib/python3.11/site-packages/keyszer/input.py", line 117, in receive_input
    on_event(event, device)
  File "/home/zenny/.local/lib/python3.11/site-packages/keyszer/transform.py", line 329, in on_event
    apply_multi_modmap(ks, context)
  File "/home/zenny/.local/lib/python3.11/site-packages/keyszer/transform.py", line 253, in apply_multi_modmap
    if modmap.conditional(context):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: 'dict' object is not callable
Exception in callback receive_input(InputDevice('...input/event4')) at /home/zenny/.local/lib/python3.11/site-packages/keyszer/input.py:102
handle: <Handle receive_input(InputDevice('...input/event4')) at /home/zenny/.local/lib/python3.11/site-packages/keyszer/input.py:102>
Traceback (most recent call last):
  File "/usr/lib/python3.11/asyncio/events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "/home/zenny/.local/lib/python3.11/site-packages/keyszer/input.py", line 117, in receive_input
    on_event(event, device)
  File "/home/zenny/.local/lib/python3.11/site-packages/keyszer/transform.py", line 329, in on_event
    apply_multi_modmap(ks, context)
  File "/home/zenny/.local/lib/python3.11/site-packages/keyszer/transform.py", line 253, in apply_multi_modmap
    if modmap.conditional(context):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: 'dict' object is not callable
Exception in callback receive_input(InputDevice('...input/event4')) at /home/zenny/.local/lib/python3.11/site-packages/keyszer/input.py:102
handle: <Handle receive_input(InputDevice('...input/event4')) at /home/zenny/.local/lib/python3.11/site-packages/keyszer/input.py:102>
Traceback (most recent call last):
  File "/usr/lib/python3.11/asyncio/events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "/home/zenny/.local/lib/python3.11/site-packages/keyszer/input.py", line 117, in receive_input
    on_event(event, device)
  File "/home/zenny/.local/lib/python3.11/site-packages/keyszer/transform.py", line 329, in on_event
    apply_multi_modmap(ks, context)
  File "/home/zenny/.local/lib/python3.11/site-packages/keyszer/transform.py", line 253, in apply_multi_modmap
    if modmap.conditional(context):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: 'dict' object is not callable
Exception in callback receive_input(InputDevice('...input/event4')) at /home/zenny/.local/lib/python3.11/site-packages/keyszer/input.py:102
handle: <Handle receive_input(InputDevice('...input/event4')) at /home/zenny/.local/lib/python3.11/site-packages/keyszer/input.py:102>
Traceback (most recent call last):
  File "/usr/lib/python3.11/asyncio/events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "/home/zenny/.local/lib/python3.11/site-packages/keyszer/input.py", line 117, in receive_input
    on_event(event, device)
  File "/home/zenny/.local/lib/python3.11/site-packages/keyszer/transform.py", line 329, in on_event
    apply_multi_modmap(ks, context)
  File "/home/zenny/.local/lib/python3.11/site-packages/keyszer/transform.py", line 253, in apply_multi_modmap
    if modmap.conditional(context):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: 'dict' object is not callable
Exception in callback receive_input(InputDevice('...input/event4')) at /home/zenny/.local/lib/python3.11/site-packages/keyszer/input.py:102
handle: <Handle receive_input(InputDevice('...input/event4')) at /home/zenny/.local/lib/python3.11/site-packages/keyszer/input.py:102>
Traceback (most recent call last):
  File "/usr/lib/python3.11/asyncio/events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "/home/zenny/.local/lib/python3.11/site-packages/keyszer/input.py", line 117, in receive_input
    on_event(event, device)
  File "/home/zenny/.local/lib/python3.11/site-packages/keyszer/transform.py", line 329, in on_event
    apply_multi_modmap(ks, context)
  File "/home/zenny/.local/lib/python3.11/site-packages/keyszer/transform.py", line 253, in apply_multi_modmap
    if modmap.conditional(context):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: 'dict' object is not callable
Exception in callback receive_input(InputDevice('...input/event4')) at /home/zenny/.local/lib/python3.11/site-packages/keyszer/input.py:102
handle: <Handle receive_input(InputDevice('...input/event4')) at /home/zenny/.local/lib/python3.11/site-packages/keyszer/input.py:102>
Traceback (most recent call last):
  File "/usr/lib/python3.11/asyncio/events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "/home/zenny/.local/lib/python3.11/site-packages/keyszer/input.py", line 117, in receive_input
    on_event(event, device)
  File "/home/zenny/.local/lib/python3.11/site-packages/keyszer/transform.py", line 329, in on_event
    apply_multi_modmap(ks, context)
  File "/home/zenny/.local/lib/python3.11/site-packages/keyszer/transform.py", line 253, in apply_multi_modmap
    if modmap.conditional(context):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: 'dict' object is not callable
Exception in callback receive_input(InputDevice('...input/event4')) at /home/zenny/.local/lib/python3.11/site-packages/keyszer/input.py:102
handle: <Handle receive_input(InputDevice('...input/event4')) at /home/zenny/.local/lib/python3.11/site-packages/keyszer/input.py:102>
Traceback (most recent call last):
  File "/usr/lib/python3.11/asyncio/events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "/home/zenny/.local/lib/python3.11/site-packages/keyszer/input.py", line 117, in receive_input
    on_event(event, device)
  File "/home/zenny/.local/lib/python3.11/site-packages/keyszer/transform.py", line 329, in on_event
    apply_multi_modmap(ks, context)
  File "/home/zenny/.local/lib/python3.11/site-packages/keyszer/transform.py", line 253, in apply_multi_modmap
    if modmap.conditional(context):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: 'dict' object is not callable
Exception in callback receive_input(InputDevice('...input/event4')) at /home/zenny/.local/lib/python3.11/site-packages/keyszer/input.py:102
handle: <Handle receive_input(InputDevice('...input/event4')) at /home/zenny/.local/lib/python3.11/site-packages/keyszer/input.py:102>
Traceback (most recent call last):
  File "/usr/lib/python3.11/asyncio/events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "/home/zenny/.local/lib/python3.11/site-packages/keyszer/input.py", line 117, in receive_input
    on_event(event, device)
  File "/home/zenny/.local/lib/python3.11/site-packages/keyszer/transform.py", line 329, in on_event
    apply_multi_modmap(ks, context)
  File "/home/zenny/.local/lib/python3.11/site-packages/keyszer/transform.py", line 253, in apply_multi_modmap
    if modmap.conditional(context):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: 'dict' object is not callable
Exception in callback receive_input(InputDevice('...input/event4')) at /home/zenny/.local/lib/python3.11/site-packages/keyszer/input.py:102
handle: <Handle receive_input(InputDevice('...input/event4')) at /home/zenny/.local/lib/python3.11/site-packages/keyszer/input.py:102>
Traceback (most recent call last):
  File "/usr/lib/python3.11/asyncio/events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "/home/zenny/.local/lib/python3.11/site-packages/keyszer/input.py", line 117, in receive_input
    on_event(event, device)
  File "/home/zenny/.local/lib/python3.11/site-packages/keyszer/transform.py", line 329, in on_event
    apply_multi_modmap(ks, context)
  File "/home/zenny/.local/lib/python3.11/site-packages/keyszer/transform.py", line 253, in apply_multi_modmap
    if modmap.conditional(context):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: 'dict' object is not callable
^Csignal INT received
joshgoebel commented 1 year ago

What is your FULL config? It seems like you have more than one multipurpose_modmap that is unconditional. Only a single multi-modmap can be default... any other blocks must be conditional.

zenny commented 1 year ago

What is your FULL config? It seems like you have more than one multipurpose_modmap that is unconditional. Only a single multi-modmap can be default... any other blocks must be conditional.

It is exactly the default config.py from examples dir in this repo, except I commented out the line that remodify CAPS_LOCK to ESC for press-release and CTRL_L when pressed down as stated above in OT. Nothing much special this far.

Is there any chance that the keyboard be remapped with the options as stated above with CAPS_LOCK = ESC/CTRL_L and ENTER=ENTER/CTRL_R and LEFT_CTRL=ESC and ESC=` etc.?

PS: Once it works, I would like to prioritize symbols over numbers (invert 1-9 with !-+) and some modifications (a combo of https://github.com/wi11dey/emacs.d/blob/master/keyboard-layout.png and https://user-images.githubusercontent.com/43980777/165561508-1b1a59a7-8d96-4f31-a2e5-a7e2eca00076.png) and some navigation like that of https://github.com/meow-edit/meow

joshgoebel commented 1 year ago

that isn't valid syntax, you only need one pair of outer {}.

multipurpose_modmap("default",
    # Enter is enter when pressed and released. Control when held down.
    {
        Key.ENTER: [Key.ENTER, Key.RIGHT_CTRL],

        # Capslock is escape when pressed and released. Control when held down.
        Key.CAPSLOCK: [Key.ESC, Key.LEFT_CTRL]
    }
    # To use this example, you can't remap capslock with modmap.
)
joshgoebel commented 1 year ago

Is there any chance that the keyboard be remapped with the options as stated above

I think so, but there are still some bugginess with the multi-mapping stuff...

zenny commented 1 year ago

that isn't valid syntax, you only need one pair of outer {}.

multipurpose_modmap("default",
    # Enter is enter when pressed and released. Control when held down.
    {
        Key.ENTER: [Key.ENTER, Key.RIGHT_CTRL],

        # Capslock is escape when pressed and released. Control when held down.
        Key.CAPSLOCK: [Key.ESC, Key.LEFT_CTRL]
    }
    # To use this example, you can't remap capslock with modmap.
)

Thanks @joshgoebel for your input, yet CAPS_LOCK does not keymapped to ESC when pressed and released and CONTROL_L when pressed!

modified ENTER works well:

KeyRelease event, serial 36, synthetic NO, window 0x4600001,
    root 0x307, subw 0x0, time 191837183, (258,367), root:(1221,386),
    state 0x0, keycode 36 (keysym 0xff0d, Return), same_screen YES,
"   XLookupString gives 1 bytes: (0d) "
    XFilterEvent returns: False

KeyPress event, serial 36, synthetic NO, window 0x4600001,
    root 0x307, subw 0x0, time 191840176, (258,367), root:(1221,386),
    state 0x0, keycode 105 (keysym 0xffe4, Control_R), same_screen YES,
    XLookupString gives 0 bytes:
    XmbLookupString gives 0 bytes:
    XFilterEvent returns: False

But CAPS_LOCK only responds to the Control_L, but does not work when pressed like 'Ctrl-x Ctrl-c' and ESC part does not display output in xev:

KeyPress event, serial 36, synthetic NO, window 0x4600001,
    root 0x307, subw 0x0, time 191852222, (258,367), root:(1221,386),
    state 0x0, keycode 37 (keysym 0xffe3, Control_L), same_screen YES,
    XLookupString gives 0 bytes:
    XmbLookupString gives 0 bytes:
    XFilterEvent returns: False

KeyRelease event, serial 36, synthetic NO, window 0x4600001,
    root 0x307, subw 0x0, time 191852222, (258,367), root:(1221,386),
    state 0x4, keycode 37 (keysym 0xffe3, Control_L), same_screen YES,
    XLookupString gives 0 bytes:
    XFilterEvent returns: False

KeyPress event, serial 36, synthetic NO, window 0x4600001,
    root 0x307, subw 0x0, time 191856942, (258,367), root:(1221,386),
    state 0x0, keycode 37 (keysym 0xffe3, Control_L), same_screen YES,
    XLookupString gives 0 bytes:
    XmbLookupString gives 0 bytes:
    XFilterEvent returns: False
joshgoebel commented 1 year ago

If you want to use ESC like a modifier you will also need to add it to Modifiers, see add_modifier... non-modifiers behave VERY differently than regular "typing keys"... that's likely part of your issue.