Macro: trick to 'hold down' a key by calling pressKey continually until an end time has stopped working

So I have the following macro, the effect of which should be emulate the holding down of the alt and printscreen keys for a duration of one second:

static void altSysrqMacro(uint8_t keyState) {
  uint32_t timeout = 1000;
  static uint32_t end_time = 0;

  if (keyToggledOn(keyState)) {
    end_time = millis() + timeout;

  if (millis() < end_time) {

(the reasons isn’t super-important right now, though if you’re interested the name gives a clue).

This used to work. It definitely worked when I first added it.

At some point in the process of upgrading to newer versions of the firmware, it stopped working. (I didn’t notice immediately since I don’t use the macro that often). The effect of it now (seen with xev) is that I get keypress events for alt and sysrq (alt+printscrn = sysrq) and then the corresponding keyrelease events for them immediately, without a 1s pause.

Anyone know why it no longer works? And/or whether there’s now any better way to accomplish the same thing?

(I’ve solved my original problem by switching to a completely different solution for the sysrq thing that doesn’t need a timing macro – – but leaving this thread open in case anyone else was using a similar timing macro for anything else and has the same original problem)

At a first glance, this should work still. Can you file an issue on GitHub, please?


1 Like