Repository navigation
[Solved] How I used macros to map my keyboard and mouse - separate key bindings #1323
ravmurth
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
First of all, my setup:
Operating System: Kubuntu 25.04
KDE Plasma Version: 6.4.5
KDE Frameworks Version: 6.14.0
Qt Version: 6.8.3
Kernel Version: 6.14.0-28-generic (64-bit)
Graphics Platform: Wayland
My keyboard is a Royal Kludge M87 and I have a Amkette Hush Pro Epic M with two extra side buttons.
I also have a laptop running Windows 11 ( where I used XMBC to configure my mouse bindings).
My requirement:
Upper Side button ( Mouse button 5, BTN_EXTRA): Page Up
Ctrl + Upper Side Button : Screenshot of Active Window
Lower Side button ( Mouse Button 4, BTN_SIDE): Page Down
Ctrl + Lower Side Button: Screenshot of Desktop
On XMBC this was a straight forward affair with two layers ( Layer 2 mapped to modifier Control). I will not go into details of XMBC here.
On Input Remapper, to achieve the same thing, I will recount the mistakes I made and how I corrected them
As per this link, https://github.com/sezanzeb/input-remapper/blob/main/readme/examples.md#combinations-spanning-multiple-devices, this was possible:
Keyboard space set(foo, 1).hold_keys(space).set(foo, 0)
Mouse middle if_eq($foo, 1, hold_keys(a), hold_keys(BTN_MIDDLE))
If you pressed, space and middle button 'a' appeared on the screen else normal mouse middle button action worked.
But what if you needed copy (Ctrl-C) when you pressed Ctrl and the lower side button and paste (Ctrl-V) when you pressed Ctrl and upper side button.
I wrote this macro:
Keyboard Preset: Control L: set(ctrlvalue, 1).hold_keys(Control_L).set(ctrlvalue, 0)
Mouse Preset: BTN_SIDE: if_eq($ctrlvalue,1, hold_keys(Control_L, key(c)), hold_keys(KEY_PAGEDOWN))
The copy action did not work but page down worked.
My suspicions:
Logs from "input-remapper-service -d" helped a lot. They confirmed that my initial suspicion about the code taking the "FALSE" path was wrong. The logs also proved the variable "ctrlvalue" was being set & read correctly AND also injected ACROSS presets. Which meant that the keyboard set the "ctrlvalue" variable correctly and the mouse preset received the value of "ctrlvalue" as "1".
Some simple tests proved that the path did enter the "TRUE" path.
Mouse Preset: BTN_SIDE: if_eq($ctrlvalue,1, key(a), key(b))
When I pressed the side button "b" appeared and when I pressed Ctrl + BTN_SIDE, "a" appeared.
Test proved.
So, clearly, the problem was in the macro I had written. On further examination of the logs, I figured that
combining hold_keys(Control_L) in the keyboard preset with "if_sq($ctrlvalue,1, hold_keys(Control_L, key(c)), hold_keys(KEY_PAGEDOWN))" in the mouse preset was the problem. The keyboard preset had already "pressed" the Ctrl key.
In my mouse preset, there was no need for me to "press it again". That is to say, "hold_keys(Control_L, key(c))" was not needed.
The system was in effect seeing Ctrl + Ctrl + C which was not a valid combo ( at least in my system) and so did nothing.
All I had to do was stop injecting the second Ctrl.
I changed my macro to : Mouse Preset: BTN_SIDE: if_eq($ctrlvalue,1, key(c), hold_keys(KEY_PAGEDOWN))
And this time, the copy worked as well the page down. Because, the system only saw "Ctrl" injected from keyboard preset plus the "C" injected from the mouse preset. All well so far.
Now, the interesting part. On a linux system ( or atleast in my linux system), the key combos for Desktop of screenshot is Left Shift + Print Key and screenshot of active window is Meta + Print.
Notice that the first key is not "Ctrl" anymore BUT my requirement is I press Ctrl + side buttons.
On the face of it, this might seem to work:
Mouse Preset: BTN_SIDE: if_eq($ctrlvalue,1, hold_keys(KEY_LEFTSHIFT, KEY_SYSRQ), hold_keys(KEY_PAGEDOWN))
But this is a problem. The chaining ( or chording) would result in "Ctrl + Shift + Print" being sent to the system and the system executing whatever application was assigned to that key combination.
I had to temporarily release Ctrl so that the system only saw "Shift + Print".
To achieve this, I modified my macro as follows:
BTN_SIDE: if_eq($ctrlvalue,1,key_up(Control_L).wait(20) .hold_keys(KEY_LEFTSHIFT,KEY_SYSRQ).wait(20).key_down(Control_L),hold_keys(KEY_PAGEDOWN))
But this caused issues as the system still saw "Ctrl" as being pressed and any subsequent actions executed as though "Ctrl" was pressed. so, pressing "V" did a paste.
I corrected this by removing the key_down and my macro became:
BTN_SIDE: if_eq($ctrlvalue,1,key_up(Control_L).wait(20) .hold_keys(KEY_LEFTSHIFT,KEY_SYSRQ).wait(20),hold_keys(KEY_PAGEDOWN))
Note that the key_up is placed in the "TRUE" path so the system "THINKS" that "Ctrl" has been released.
Now, there is no key_down and the system has already entered the "TRUE" path so it simply executes key_up (Ctrl) which releases the Ctrl key and then a brief wait, then the Shift + Print key combo.
When hold_keys resumes execution, it simply emits the same key_up event ( which in effect has to do nothing ).
My final macro combinations:
BTN_SIDE (Mouse Button 4) : if_eq($ctrlvalue,1,key_up(Control_L).wait(20) .hold_keys(KEY_LEFTSHIFT,KEY_SYSRQ).wait(20),hold_keys(KEY_PAGEDOWN))
BTN_EXTRA ( Mouse Button 5): if_eq($ctrlvalue,1,key_up(Control_L).wait(20) .hold_keys(KEY_LEFTMETA,KEY_SYSRQ).wait(20),hold_keys(KEY_PAGEUP))
Hope this is of help to someone. Please feel free to comment or DM for more details
All reactions