Macros with modifiers

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?

Keyboard.wasModifierActive(Key mapped_key);

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

Oh ok, it’s wasModifierActive(Key_LeftShift).

These threads are also helpful:

1 Like

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

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);

           ^

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.

1 Like