Kill macro (OneShot) after a specific time?

I use OneShot for Shift, which works great in general. But in some use cases the OneShot Shift stays on longer than wanted.

For example when marking multiple items one can press Shift and then click on the last line (for example in the Explorer). When I do this with the integrated mouse function the Shift is correctly released. When I use an external mouse the Shift stays active “forever”, which is not wanted. I guess there is no way that the UHK recognizes the click of an external mouse. As a workaround I want to kill the OneShot after a specific time, when no key was pressed or no (internal mouse) click happened.

The following was one of a few unsuccessful attempts. Which command am I missing or what is wrong with my attempt?

set backlight.constantRgb.rgb 255 0 0
oneShot holdKey iS-
set backlight.strategy functional
// following lines are supposed to kill the macro, when no key is pressed in 750 ms.
ifPlaytime 750  
set backlight.strategy functional
break

EDIT, when it is not possible to undo the Shift being active one could add tapKey Shift in the break-routine!? But that does also not work.

It does not work because the oneShot blocks while it waits for another key to be activated, so the lines that are supposed to kill the macro don’t get executed until the oneShot holdKey finishes.

Regarding tapKey Shift, if you mean that the tapKey would trigger the oneShot and thus end it, then also no. The tapKey command only produces scancodes. It does not actually simulate a key press.

As to the solution, I guess we can add a configurable timeout.

If you insist on inventing a macro workaround, then you will need to start another macro using the fork command, and then after delaying for 750 ms either kill all macros or use activateKeyPostponed to trigger some key and thus oneShot.

Thanks for the answer!

That would be great Karel! :slight_smile:

For the moment I have the workaround to be able to kill the waiting Shift key, by pressing an extra (standard) Shift key I have currently in my base layer. But a timeout option would be super helpful to eliminate the need to be extra aware of the situations like described.

Mmh, I do not understand that. tapKey a will produce an a character. Why would tapKey Shift not produce a Shift-keypress then?

By a “keypress” I mean the act of physical activation of a switch, not an act of copying a number (scancode) into a usb report.

Makes sense now?

Sort of. :keyboard: