reddit / emacs

Unable to make Emacs macro key work with QMK-based keyboard

DeerRepresentative91 · 2022-11-12 12:19
Posting here as well as maybe one of you can help. I have a ZSA Moonlander keyboard. With their online configurator, I set up a key to run the Emacs macro "C-x b", that is "Press Ctrl-X, then press B". But when I use it, it emits "x" and "b" separately. I downloaded the source code for my firmware and it looks OK to me: case ST_MACRO_2: if (record->event.pressed) { SEND_STRING(SS_RCTL(SS_TAP(X_X)) SS_DELAY(100) SS_TAP(X_B)); } Taps Right Ctrl with X, waits 100ms, then taps B. Which exactly what I want it to do. What am I missing? I tried inspecting the keyboard events and it still looks OK to me. Dump from evtest when I press that macro key: https://pastebin.com/fJp5kyR4 Is it executed too fast for Emacs?
DeerRepresentative91 · 2022-11-12 12:28
Mmmm.. seems like it's an Emacs bug, because it works in terminal mode with `emacs -nw`, but the keystrokes are too quick apparently for Emacs on GNOME Wayland... Is there a setting somewhere to make GUI Emacs more reactive to keystrokes? EDIT: it works 50% of the time in Emacs terminal, 10% of the time in the GUI...
mickeyp · 2022-11-12 12:42
Anything involving delays in keyboard event code is likely to misfire at some point. I recommend you instead create a dedicated key binding in Emacs for this and then a dedicated keyboard shortcut in Moonlander. Like `control + hyper b` or something.
_ianna · 2022-11-12 13:15
Better way is to use the unused Hyper modifier and make they keyboard emit something like H-b and then bind H-b to show buffers. Can also do like, H-C-M-S if you run out of room with just Hyper lol. I used to use Hyper for quick binds for registers since I used them so much.
ieure · 2022-11-12 17:26
I agree with the others, likely your timing is off here. The QMK macro looks good to me. If you're on Linux, you can use xev to see the actual events the keyboard is sending, which might help narrow down the issue. My gut is that 100ms in between events should be plenty, though as others have said, simplifying your binding is a good idea. Hyper isn't a great suggestion, though, since the USB protocol can't represent it. Depending on your OS, you can do a dance of mapping Hyper to a different key and set QMK to send that key, but this can be a difficult thing to manage on some operating systems.
plm314 · 2022-11-12 22:19
Would this work? SEND_STRING(SS_RCTL("x")”b”); Alternatively, maybe try doubling the delay. How do you like the keyboard with Emacs so far?
french_pressed · 2022-11-13 12:38
> How do you like the keyboard with Emacs so far? Not OP but I've got the Ergodox EZ and really like it. I use standard keybindings and the thumb clusters make those much more comfortable.
flamingbear · 2022-11-14 19:18
Also not the original poster, but after some learning curve, I love it.