arduino-libraries / Keyboard

GNU Lesser General Public License v3.0
223 stars 157 forks source link

Pressing both SHIFT and ALT-GR at the same time to type specific characters on MAC #86

Closed felop closed 9 months ago

felop commented 9 months ago

I read in KeyboardLayout.h that it was not possible to use both SHIFT and ALT_GR on the same character. I was trying to emulate a Backslash on a French Mac keyboard (normally typed by pressing Option+Shift+colon) and tried to modify the KeyboardLayout_fr_FR.cpp file by adding: 0x37|SHIFT|ALT_GR, // bslash but obviously didn't work. Is there another way to do this?

edgar-bonet commented 9 months ago

As explained in the pull request that introduced the possibility to define multiple keyboard layouts (#53), supporting key combinations that use both AltGr and Shift would require growing the ASCII map to 16 bits per cell. It may also require significant changes in the code, so it is not completely trivial.

There is a (admittedly inconvenient) workaround though. You can explicitly tell the library what keys it should press:

// Press Option-Shift-colon.
Keyboard.press(KEY_RIGHT_ALT);  // Option key on Mac
Keyboard.press(KEY_LEFT_SHIFT);
Keyboard.press(':');
Keyboard.releaseAll();