Hi. UHK noob here. Is there some way to run a macro when any key is hit?
I managed to mirror my zoom mic state onto the backlight, such that the keyboard is constantrgb red when i am muted, constantrgb green when live, and functional when not in a meeting.
As a next level of silliness, I’d like to switch to functional when I start typing while mute (maybe keep a couple keys red). I dont want to have to map every key separately to a macro that first do the key’s normal thing and then run a macro, for all layers and modifiers. Is there a way to do this, i.e. run a macro after any keystroke?
In case there isn’t, what is the most efficient way for just some frequently used keys to do the above. For example, only make all the modifier keys (CASG) turn the backlight back to functional, while still have them behave like normal?
You can use active-waiting black magic, say resetOnKeystroke:
postponeKeys ifNotPending 1 goTo $currentAddress
set backlight.strategy functional
Then you will want to guard it against reentrancy. Otherwise, after a couple of meet state switches, you will get a bunch of waiting macros.
The full macro with reentrancy guard:
if ($resetOnKeystrokeActive) break
setVar resetOnKeystrokeActive true
postponeKeys ifNotPending 1 goTo $currentAddress
set backlight.strategy functional
setVar resetOnKeystrokeActive false
(Cleaner alternative: try to persuade us (me) to refactor the delayUntil* commands branch to support something like delayUntilKeystateChange or delayUntil keystateChange, which would allow you to skip that ugly active wait loop.)
In either case, run that macro from your backlight machinery. Something like fork resetOnKeystroke. It will wait for first key action and then switch back to functional backlight.