# Macros with modifiers

**URL:** <https://community.keyboard.io/t/macros-with-modifiers/909>\
**Category:** Programming\
**Created:** [December 30, 2017, 7:44am UTC](https://community.keyboard.io/t/macros-with-modifiers/909 "2017-12-30T07:44:06Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![fire](https://avatars.discourse-cdn.com/v4/letter/f/67e7ee/32.png) [@fire](https://community.keyboard.io/u/fire)\
**Post date:** [December 30, 2017, 7:44am UTC](https://community.keyboard.io/t/macros-with-modifiers/909/1 "2017-12-30T07:44:06Z")

</div>

I would like to make a macro that does one thing when shift is pressed and another thing when shift is not pressed. Is there a way to do that?

How do I detect what modifiers are pressed when I run the macro?

---

<div class="post-metadata">

**Author:** ![merlin](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/merlin/32/3416_2.png) [@merlin](https://community.keyboard.io/u/merlin)\
**Post date:** [December 30, 2017, 2:39pm UTC](https://community.keyboard.io/t/macros-with-modifiers/909/2 "2017-12-30T14:39:14Z")

</div>

```auto
Keyboard.wasModifierActive(Key mapped_key);

```

---

<div class="post-metadata">

**Author:** ![fire](https://avatars.discourse-cdn.com/v4/letter/f/67e7ee/32.png) [@fire](https://community.keyboard.io/u/fire)\
**Post date:** [December 30, 2017, 8:58pm UTC](https://community.keyboard.io/t/macros-with-modifiers/909/3 "2017-12-30T20:58:52Z")

</div>

Thanks - I’m not sure I understand how that works.

Do I use that within a macro?

Does it return true if any modifier was on? How do I determine which modifier was on? Do I use wasLeftShiftActive(), was LeftControlActive(), etc.?

---

<div class="post-metadata">

**Author:** ![fire](https://avatars.discourse-cdn.com/v4/letter/f/67e7ee/32.png) [@fire](https://community.keyboard.io/u/fire)\
**Post date:** [December 30, 2017, 9:10pm UTC](https://community.keyboard.io/t/macros-with-modifiers/909/4 "2017-12-30T21:10:55Z")

</div>

Oh ok, it’s wasModifierActive(Key\_LeftShift).

These threads are also helpful:

> [@Is there a way to change the effect of chorded modifier keys without making them layer keys?](https://community.keyboard.io/t/is-there-a-way-to-change-the-effect-of-chorded-modifier-keys-without-making-them-layer-keys/831/2):
>
> The easiest, in my opinion, would be a custom event handler hook, something along these lines: Key customControls(Key mapped\_key, byte row, byte col, uint8\_t key\_state) { // If none of the controls are pressed, fall through. if (!kaleidoscope::hid::wasModifierKeyActive(Key\_LeftControl) && !kaleidoscope::hid::wasModifierKeyActive(Key\_RightControl) { return mapped\_key; // Either left or right control is active! // If the key isn't C, fall through if (mapped\_key != Key\_C) …

> [@Some funky shift customizations I’d like to make slight\_smile](https://community.keyboard.io/t/some-funky-shift-customizations-i-d-like-to-make/716/4):
>
> Yeah… hm. Perhaps releaseing shifts, then sending a report, then the backslash would help? And do the release+report combo only on keyToggledOn, not while keyIsPressed? Just a hunch. (Sorry for the brevity, kinda time-pressed here and can’t elaborate :/)

> [@Mapping International Characters](https://community.keyboard.io/t/mapping-international-characters/556/49):
>
> What do you get when you type Fn+shift+unicode macro when using that sketch?

---

<div class="post-metadata">

**Author:** ![merlin](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/merlin/32/3416_2.png) [@merlin](https://community.keyboard.io/u/merlin)\
**Post date:** [December 31, 2017, 3:09pm UTC](https://community.keyboard.io/t/macros-with-modifiers/909/5 "2017-12-31T15:09:00Z")

</div>

Sorry for not providing more information; I was short on time just then.

---

<div class="post-metadata">

**Author:** ![fire](https://avatars.discourse-cdn.com/v4/letter/f/67e7ee/32.png) [@fire](https://community.keyboard.io/u/fire)\
**Post date:** [December 31, 2017, 10:43pm UTC](https://community.keyboard.io/t/macros-with-modifiers/909/6 "2017-12-31T22:43:36Z")

</div>

If I use kaleidoscope::hid::wasModifierKeyActive it works fine. But with Keyboard.wasModifierActive I get the following error:

```
E:\User\Documents\Arduino\Model01-Firmware-Jeremy\Model01-Firmware-Jeremy.ino: In function 'const macro_t* macroAction(uint8_t, uint8_t)':

Model01-Firmware-Jeremy:683: error: no matching function for call to 'Keyboard_::wasModifierActive(Key)'

         if (Keyboard.wasModifierActive(Key_LeftShift) || Keyboard.wasModifierActive(Key_RightShift))

                                                     ^

E:\User\Documents\Arduino\Model01-Firmware-Jeremy\Model01-Firmware-Jeremy.ino:683:53: note: candidate is:

In file included from C:\Users\User\AppData\Local\Arduino15\packages\keyboardio\hardware\avr\1.22.0\libraries\KeyboardioHID\src/KeyboardioHID.h:48:0,

                 from C:\Users\User\AppData\Local\Arduino15\packages\keyboardio\hardware\avr\1.22.0\libraries\Kaleidoscope\src/key_defs.h:16,

                 from C:\Users\User\AppData\Local\Arduino15\packages\keyboardio\hardware\avr\1.22.0\libraries\Kaleidoscope\src/key_events.h:5,

                 from C:\Users\User\AppData\Local\Arduino15\packages\keyboardio\hardware\avr\1.22.0\libraries\Kaleidoscope\src/Kaleidoscope.h:24,

                 from E:\User\Documents\Arduino\Model01-Firmware-Jeremy\Model01-Firmware-Jeremy.ino:26:

C:\Users\User\AppData\Local\Arduino15\packages\keyboardio\hardware\avr\1.22.0\libraries\KeyboardioHID\src/MultiReport/Keyboard.h:60:11: note: boolean Keyboard_::wasModifierActive(uint8_t)

   boolean wasModifierActive(uint8_t k);

           ^
```

---

<div class="post-metadata">

**Author:** ![craigdissel](https://avatars.discourse-cdn.com/v4/letter/c/b5ac83/32.png) [@craigdissel](https://community.keyboard.io/u/craigdissel)\
**Post date:** [January 1, 2018, 10:01pm UTC](https://community.keyboard.io/t/macros-with-modifiers/909/7 "2018-01-01T22:01:23Z")

</div>

> [@fire](#):
>
> If I use kaleidoscope::hid::wasModifierKeyActive it works fine.

I believe this is the “correct” / encouraged way to do this (it uses the Kaleidoscope HID facade). User code should “not” use HID objects like `Keyboard` directly. Someone else can correct me if I’m wrong.
