# Are there docs on key states, keyToggledOn, key\_is\_pressed, key\_toggled\_off anywhere?

**URL:** <https://community.keyboard.io/t/are-there-docs-on-key-states-keytoggledon-key-is-pressed-key-toggled-off-anywhere/890>\
**Category:** Programming\
**Created:** [December 20, 2017, 9:46pm UTC](https://community.keyboard.io/t/are-there-docs-on-key-states-keytoggledon-key-is-pressed-key-toggled-off-anywhere/890 "2017-12-20T21:46:41Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![jhurwitz](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/jhurwitz/32/2046_2.png) [@jhurwitz](https://community.keyboard.io/u/jhurwitz)\
**Post date:** [July 10, 2018, 3:48am UTC](https://community.keyboard.io/t/are-there-docs-on-key-states-keytoggledon-key-is-pressed-key-toggled-off-anywhere/890/7 "2018-07-10T03:48:59Z")

</div>

> [@algernon](#):
>
> This should release the next cycle after you release the key.

My testing indicates that this is true if the macro is a single key, but not if the macro contains multiple keys.

For demonstration purposes, I’ve taken the default firmware (at commit 11676727) and made just a single change:

```
diff --git a/Model01-Firmware.ino b/Model01-Firmware.ino
index bc45ee3..6a182e0 100644
--- a/Model01-Firmware.ino
+++ b/Model01-Firmware.ino
@@ -236,7 +236,8 @@ const macro_t *macroAction(uint8_t macroIndex, uint8_t keyState) {
     break;

   case MACRO_ANY:
- anyKeyMacro(keyState);
+ if (keyIsPressed(keyState))
+ return MACRO(D(A));
     break;
   }
   return MACRO_NONE;

```

This works as expected. I’m on a Mac running [Key Codes](https://manytricks.com/keycodes/) to inspect keyboard inputs, and pressing the any key works identically to pressing the A key: I see a Key Down event, then a brief pause, then Key Down (Repeat) events, and finally (when I release the key) a Key Up event. I would also add that the Key Down (Repeat) events are on the order of magnitude of 10 per second.

Let’s instead change this macro to: `return MACRO(D(A), D(B));`. Now I get something completely different: A Key Down event for A when I first press any, and a Key Up event for A when I release any, but in the interim, I’m getting alternating Key Down and Key Up events for B on the order of magnitude of 100 per second or more – likely, one per scan cycle.

Now admittedly this is a contrived example, but modifier + key is significantly less contrived. If I repeat this experiment with: `return MACRO(D(LeftGui), D(A));` then I get a Modifier Change event when I press and release the any button, and then Key Down/Up events for A every cycle. And likewise, if I try `return MACRO(D(A), D(LeftGui));` then I get Key Down/Up for A when I press and release the any button, and two Modifier Change events every cycle.

What I’m ultimately trying to build at the moment is a macro that maps Ctrl+Tab to a certain combination of keys. (And then next I’m going to work on Cmd+Tab, but that’s significantly more complicated for several reasons, so I’m starting with Ctrl+Tab. And yes, I’ve already read the code examples for Cmd/Alt+Tab both [here](https://community.keyboard.io/t/just-act-normal-in-a-macro/892/13) and [here](https://github.com/keyboardio/Kaleidoscope/tree/master/examples/AppSwitcher).)

Let’s use Chrome on my Mac as an example. When I press _and hold_ Ctrl+Tab using the native keyboard, Chrome will switch to the next tab, pause momentarily, and then start to rapidly advance tabs repeatedly. When I look at the Key Codes app, this first tab switch corresponds to the initial Key Down event, and then the later (rapid) tab switches correspond to the approximately ~10 per second Key Down (Repeat) events. I’m not sure what layer (eg, I’m not even sure if it’s hardware or software) is responsible for generating these Key Down (Repeat) events – but whatever it is, I can’t seem to get that to happen when using Kaleidoscope macros with multiple keys.

---

_[View the full topic](https://community.keyboard.io/t/are-there-docs-on-key-states-keytoggledon-key-is-pressed-key-toggled-off-anywhere/890)._
