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

**URL:** <https://community.keyboard.io/t/macro-trick-to-hold-down-a-key-by-calling-presskey-continually-until-an-end-time-has-stopped-working/3375>\
**Category:** Programming\
**Created:** [December 4, 2019, 11:13pm UTC](https://community.keyboard.io/t/macro-trick-to-hold-down-a-key-by-calling-presskey-continually-until-an-end-time-has-stopped-working/3375 "2019-12-04T23:13:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![coiley](https://avatars.discourse-cdn.com/v4/letter/c/0ea827/32.png) [@coiley](https://community.keyboard.io/u/coiley)\
**Post date:** [December 4, 2019, 11:13pm UTC](https://community.keyboard.io/t/macro-trick-to-hold-down-a-key-by-calling-presskey-continually-until-an-end-time-has-stopped-working/3375/1 "2019-12-04T23:13:40Z")

</div>

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) {
    kaleidoscope::hid::pressKey(Key_LeftAlt);
    kaleidoscope::hid::pressKey(Key_PrintScreen);
  }
}

```

(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?

---

<div class="post-metadata">

**Author:** ![coiley](https://avatars.discourse-cdn.com/v4/letter/c/0ea827/32.png) [@coiley](https://community.keyboard.io/u/coiley)\
**Post date:** [December 4, 2019, 11:42pm UTC](https://community.keyboard.io/t/macro-trick-to-hold-down-a-key-by-calling-presskey-continually-until-an-end-time-has-stopped-working/3375/2 "2019-12-04T23:42:14Z")

</div>

(I’ve solved my original problem by switching to a completely different solution for the sysrq thing that doesn’t need a timing macro – [https://github.com/SimonWoolf/Model01-Firmware/commit/2593675fcef0869882047fa5f2130560222cbc99](https://github.com/SimonWoolf/Model01-Firmware/commit/2593675fcef0869882047fa5f2130560222cbc99) – but leaving this thread open in case anyone else was using a similar timing macro for anything else and has the same original problem)

---

<div class="post-metadata">

**Author:** ![algernon](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/algernon/32/4404_2.png) [@algernon](https://community.keyboard.io/u/algernon)\
**Post date:** [December 5, 2019, 1:12am UTC](https://community.keyboard.io/t/macro-trick-to-hold-down-a-key-by-calling-presskey-continually-until-an-end-time-has-stopped-working/3375/3 "2019-12-05T01:12:40Z")

</div>

> [@coiley](#):
>
> Anyone know why it no longer works? And/or whether there’s now any better way to accomplish the same thing?

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

---

<div class="post-metadata">

**Author:** ![coiley](https://avatars.discourse-cdn.com/v4/letter/c/0ea827/32.png) [@coiley](https://community.keyboard.io/u/coiley)\
**Post date:** [December 7, 2019, 7:02pm UTC](https://community.keyboard.io/t/macro-trick-to-hold-down-a-key-by-calling-presskey-continually-until-an-end-time-has-stopped-working/3375/4 "2019-12-07T19:02:41Z")

</div>

Sure: [https://github.com/keyboardio/Kaleidoscope/issues/757](https://github.com/keyboardio/Kaleidoscope/issues/757)
