# Checking if shift is held down in a macro

**URL:** <https://community.keyboard.io/t/checking-if-shift-is-held-down-in-a-macro/5075>\
**Category:** Programming\
**Created:** [October 11, 2021, 9:14am UTC](https://community.keyboard.io/t/checking-if-shift-is-held-down-in-a-macro/5075 "2021-10-11T09:14:36Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zindar](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/zindar/32/3470_2.png) [@Zindar](https://community.keyboard.io/u/Zindar)\
**Post date:** [October 11, 2021, 9:14am UTC](https://community.keyboard.io/t/checking-if-shift-is-held-down-in-a-macro/5075/1 "2021-10-11T09:14:36Z")

</div>

Hi.

I’m trying to make a macro that should do  
alt-u a  
This is because that will create the character ä on a mac with US layout

This is easy to do with the following code

```auto
  case MACRO_SWE_AE:
    if (keyToggledOff(keyState)) {
      return MACRO(I(25), D(LeftAlt), T(U), U(LeftAlt), T(A));
    }
    break; 

```

The problem now is that if I hold down shift and hit this button, it will obviously do alt-shift-u which is wrong.

So I need to check if shift is held, release it in code, do the macro, then hold it again.  
I did do the same thing in QMK but fail to find how to do it in the documentation for Kaleidoscope.

Thankful for any help

---

<div class="post-metadata">

**Author:** ![alfalfasprossen](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/alfalfasprossen/32/2101_2.png) [@alfalfasprossen](https://community.keyboard.io/u/alfalfasprossen)\
**Post date:** [October 11, 2021, 10:24pm UTC](https://community.keyboard.io/t/checking-if-shift-is-held-down-in-a-macro/5075/2 "2021-10-11T22:24:38Z")

</div>

I think this should still work to check if shift is currently active.

```cpp
    if (kaleidoscope::Runtime.hid().keyboard().isModifierKeyActive(Key_LeftShift) ||
        kaleidoscope::Runtime.hid().keyboard().isModifierKeyActive(Key_RightShift))

```

Releasing it can be done with the macro then like `MACRO(U(LeftShift), U(RightShift) ...`.

---

<div class="post-metadata">

**Author:** ![Zindar](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/zindar/32/3470_2.png) [@Zindar](https://community.keyboard.io/u/Zindar)\
**Post date:** [October 12, 2021, 10:14am UTC](https://community.keyboard.io/t/checking-if-shift-is-held-down-in-a-macro/5075/3 "2021-10-12T10:14:00Z")

</div>

Thank you. That works perfectly

---

<div class="post-metadata">

**Author:** ![lasse](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/lasse/32/185_2.png) [@lasse](https://community.keyboard.io/u/lasse)\
**Post date:** [October 13, 2021, 9:36am UTC](https://community.keyboard.io/t/checking-if-shift-is-held-down-in-a-macro/5075/4 "2021-10-13T09:36:23Z")

</div>

I use the macro with the compose key in osx to do danish characters:

> <https://github.com/lldata/Model01-Firmware/blob/osx/Model01-Firmware.ino#L285>

---

<div class="post-metadata">

**Author:** ![Zindar](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/zindar/32/3470_2.png) [@Zindar](https://community.keyboard.io/u/Zindar)\
**Post date:** [October 13, 2021, 10:08am UTC](https://community.keyboard.io/t/checking-if-shift-is-held-down-in-a-macro/5075/5 "2021-10-13T10:08:46Z")

</div>

This means that you have to use a custom keyboard layout on your mac, right?  
That’s what I do currently but I would like to use the default US layout. Right now I have a custom colemak layout that has some extra ways to do the swedish chars and that works fine but it’s just not as fun.

Also, as a bonus, by using the default US layout and still getting colemak, with a way to do swedish chars, means that I can connect the keyboard to an ipad and still getting everything working

---

<div class="post-metadata">

**Author:** ![lasse](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/lasse/32/185_2.png) [@lasse](https://community.keyboard.io/u/lasse)\
**Post date:** [October 14, 2021, 8:35am UTC](https://community.keyboard.io/t/checking-if-shift-is-held-down-in-a-macro/5075/6 "2021-10-14T08:35:03Z")

</div>

This is embarrassing. It looks like I forgot how my own keyboard works 😕

On second thought (and investigation) it turns out that I don’t use the compose key anymore. I just rely on the alt keys in mac os. But on windows I do/did rely on the compose key.

I am also a colemak user, but I set the keyboard layout from the OS.

I have really spent a long time trying to key my layout right and especially mapping of danish characters have been really painful!
