0

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?

Codebeat
  • 6,501
  • 6
  • 57
  • 99

1 Answers1

0

When you press capslock on keyboard #1, keyboard #2 will detect this state.

Thats because the current LED state is transmitted to all keyboards by the OS. But only the LED state is transmitted and not the key state.

Turbo J
  • 7,563
  • 1
  • 23
  • 43