You are not logged in.

#1 2022-07-19 01:24:09

Tempel
Member
Registered: 2010-01-19
Posts: 10

[solved] Using keys as mouse buttons in Wayland/Sway

My keyboard has three media keys that I don't use, so I like to use them as extra mouse buttons instead.  I was previously using xmonad as my window manager, and I configured it to have those keys execute xte (from the xautomation package) to emit mouse button events.  I'm trying to switch from xmonad to Sway, and I set up the same keybindings to xte, but of course that only works in xwayland windows, not in native Wayland windows.

So is there a way to emit mouse clicks that Wayland windows will recognize?  Preferably in a way that's user-specific, as I have other users on this machine, but I'll take system-wide settings if necessary.

Last edited by Tempel (2022-07-19 10:54:18)

Offline

#2 2022-07-19 01:28:48

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,523
Website

Re: [solved] Using keys as mouse buttons in Wayland/Sway

No: there is no "Wayland" to interact with as there is an Xorg under X.  This would have to either be a feature of the compositor (and sway has no such commands) or you'd need to interact with /dev/uinput and/or libinput directly (which, as an aside, would then work under Xorg or any linux wayland compositor).  However, I'm not aware of any existing tools to simulate libinput events.

EDIT: scratch that - it appears sway does have a cursor event simulation feature built in - I had never seen it documented, but apparently it's there with commands like 'seat * cursor press buttonN' where N is a number.

Last edited by Trilby (2022-07-19 01:34:38)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#3 2022-07-19 10:53:52

Tempel
Member
Registered: 2010-01-19
Posts: 10

Re: [solved] Using keys as mouse buttons in Wayland/Sway

Trilby wrote:

seat * cursor press buttonN

That's exactly what I need.  Thanks for spotting that, I'm embarrassed I missed it in the documentation.  For others' reference, here's how the relevant section of my config looks now:

bindsym --no-repeat XF86AudioPrev seat * cursor press button1
bindsym --no-repeat --release XF86AudioPrev seat * cursor release button1
bindsym --no-repeat XF86AudioPlay seat * cursor press button2
bindsym --no-repeat --release XF86AudioPlay seat * cursor release button2
bindsym --no-repeat XF86AudioNext seat * cursor press button3
bindsym --no-repeat --release XF86AudioNext seat * cursor release button3

Also for others' reference, in my searching I came across evemu which emulates input events at a lower level, but it looks to be much more complicated to set up than the config above.

Offline

Board footer

Powered by FluxBB