An USB keyboard for example is a shared device within a system. Several keyboards is possible and they share the num, scroll and capslock states. When you press capslock on keyboard #1, keyboard #2 will detect this state.
For an emulated USB keyboard device (using the Trinket library), you can check these values by using:
typedef struct { bool caps,num,scroll; } TKeyboardLEDState;
.....
TKeyboardLEDState usbGetKeyboardLedState()
{
uint8_t iState = TrinketHidCombo.getLEDstate();
TKeyboardLEDState tResult;
tResult.caps = (iState & (1<< KB_LED_CAPS));
tResult.num = (iState & (1<< KB_LED_NUM));
tResult.scroll = (iState & (1<< KB_LED_SCROLL));
return tResult;
}
.......
void loop()
{
TKeyboardLEDState recKeybLEDstate = usbGetKeyboardLedState();
if( recKeybLEDstate.caps )
{
// do something
}
}
Question:
So I wonder if I can do this with ANY key or is this completely impossible? If not, why not? If yes, how can I do this?