mooz / xkeysnail

Yet another keyboard remapping tool for X environment
891 stars 112 forks source link

Bind mouse buttons? #85

Open dufferzafar opened 4 years ago

dufferzafar commented 4 years ago

I can't seem to figure out to bind mouse buttons. Here is what I've tried (and it doesn't work):

In this case nothing happens:

define_keymap(re.compile("Zeal"), {
    K("Btn_RIGHT"): launch(["xmessage", "boo"]),
}, "Zeal")

While in this case, error happens:


define_keymap(re.compile("Zeal"), {
    K("C+Btn_RIGHT"): launch(["xmessage", "boo"]),
}, "Zeal")
Traceback (most recent call last):
  File "/home/dufferzafar/.local/bin/xkeysnail", line 6, in <module>
    cli_main()
  File "/home/dufferzafar/.local/pipx/venvs/xkeysnail/lib/python3.8/site-packages/xkeysnail/__init__.py", line 61, in cli_main
    eval_file(args.config)
  File "/home/dufferzafar/.local/pipx/venvs/xkeysnail/lib/python3.8/site-packages/xkeysnail/__init__.py", line 6, in eval_file
    exec(compile(file.read(), path, 'exec'), globals())
  File "/home/dufferzafar/.dotfiles/snail.py", line 25, in <module>
    K("C+Btn_RIGHT"): launch(["xmessage", "boo"]),
  File "/home/dufferzafar/.local/pipx/venvs/xkeysnail/lib/python3.8/site-packages/xkeysnail/transform.py", line 145, in K
    key = getattr(Key, key_str)
  File "/usr/lib/python3.8/enum.py", line 341, in __getattr__
    raise AttributeError(name) from None
AttributeError: C+BTN_RIGHT
Exception ignored in: <function InputDevice.__del__ at 0x7f59ec2e74c0>
Traceback (most recent call last):
  File "/home/dufferzafar/.local/pipx/venvs/xkeysnail/lib/python3.8/site-packages/evdev/device.py", line 159, in __del__
  File "/home/dufferzafar/.local/pipx/venvs/xkeysnail/lib/python3.8/site-packages/evdev/device.py", line 304, in close
  File "/home/dufferzafar/.local/pipx/venvs/xkeysnail/lib/python3.8/site-packages/evdev/eventio_async.py", line 54, in close
  File "/usr/lib/python3.8/asyncio/events.py", line 722, in get_event_loop_policy
  File "/usr/lib/python3.8/asyncio/events.py", line 715, in _init_event_loop_policy
ImportError: sys.meta_path is None, Python is likely shutting down
arest commented 4 years ago

Same here Traceback (most recent call last): File "/usr/local/bin/xkeysnail", line 6, in <module> cli_main() File "/usr/local/lib/python3.8/dist-packages/xkeysnail/__init__.py", line 61, in cli_main eval_file(args.config) File "/usr/local/lib/python3.8/dist-packages/xkeysnail/__init__.py", line 5, in eval_file with open(path, "rb") as file: FileNotFoundError: [Errno 2] No such file or directory: '' Exception ignored in: <function InputDevice.__del__ at 0x7feeca570700> Traceback (most recent call last): File "/usr/local/lib/python3.8/dist-packages/evdev/device.py", line 159, in __del__ File "/usr/local/lib/python3.8/dist-packages/evdev/device.py", line 304, in close File "/usr/local/lib/python3.8/dist-packages/evdev/eventio_async.py", line 54, in close File "/usr/lib/python3.8/asyncio/events.py", line 722, in get_event_loop_policy File "/usr/lib/python3.8/asyncio/events.py", line 715, in _init_event_loop_policy ImportError: sys.meta_path is None, Python is likely shutting down

097115 commented 2 years ago

K("C+Btn_RIGHT")

As I understand, to avoid the error, it should be not + there but -.

However, I'm still failing to use a map like this:

K("LSuper-BTN_LEFT"): K("BTN_MIDDLE"),

It throws no errors but just doesn't work (clicking the Left button with the left Super key presses acts just like the regular Left button).

joshgoebel commented 2 years ago

I can't seem to figure out to bind mouse buttons.

Are you using --device to make sure it binds to your mouse? By default we only work with keyboards and purposely exclude mice...

097115 commented 2 years ago

@joshgoebel

Are you using --device to make sure it binds to your mouse?

Could you please suggest what should I pass here for a touchpad?

joshgoebel commented 2 years ago

You'd have to look at your device list when you run xkeysnail and figure out which device it is and then specify that with --device... evtest might help you test to make sure you find the right device.

097115 commented 2 years ago

@joshgoebel , thanks, it works :)

For the reference, --devices /dev/input/event3 /dev/input/event4 did it, where event3 is "AT Translated Set 2 keyboard", and event4 is "PS/2 Generic Mouse" (and not /dev/input/event5, which is "SynPS/2 Synaptics TouchPad").

joshgoebel commented 2 years ago

Touchpads can't work with xkeysnail because it doesn't allow the cursor movement thru, so your touchpad would only click and not move....