Skip to content

Adding support for getting numlock/capslock/scrolllock states #43

Open
@T-vK

Description

@T-vK

I would like to keep ESP32-BLE-Keyboard compatible with the Keyboard library and now we're about to add support for retrieving the numlock, capslock and scrolllock states.
So I would like to agree on a set of methods that we try to implement in both libraries.

Would you be okay with a method called setLedChangeCallBack that would allow providing a callback function?

Keyboard.setLedChangeCallBack(KbdLedCb);

E.g.

#include <Keyboard.h>

void onKeyboardLedChange(KbdLeds *kbls)
{
  if (kbls->bmNumLock == HIGH)
     Seriel.println("Numlock On!");
  else
     Seriel.println("Numlock Off!");

  if (kbls->bmCapsLock == HIGH)
     Seriel.println("CapsLock On!");
  else
     Seriel.println("CapsLock Off!");

  if (kbls->bmScrollLock == HIGH)
     Seriel.println("ScrollLock On!");
  else
     Seriel.println("ScrollLock Off!");
}

void setup()
{
  Serial.begin(9600);
  Keyboard.begin();
  Keyboard.setLedChangeCallBack(KbdLedCb);
}

void loop()
{
}

and 3 methods to retrieve the states of the lock keys manually without a callback:

Keyboard.GetNumLockState();
Keyboard.GetCapsLockState();
Keyboard.GetScrollLockState();

e.g.

#include <Keyboard.h>

void setup()
{
  Serial.begin(9600);
  Keyboard.begin();
}

void loop()
{
  bool numLockState = Keyboard.GetNumLockState();
  bool capsLockState = Keyboard.GetCapsLockState();
  bool scrollLockState = Keyboard.GetScrollLockState();
  if (numLockState == HIGH)
     Seriel.println("Numlock On!");
  else
     Seriel.println("Numlock Off!");

  if (capsLockState == HIGH)
     Seriel.println("CapsLock On!");
  else
     Seriel.println("CapsLock Off!");

  if (scrollLockState == HIGH)
     Seriel.println("ScrollLock On!");
  else
     Seriel.println("ScrollLock Off!");
  delay(1000);
}

Maybe it would make more sense to use true/false instead of HIGH/LOW?
Or different names for the methods?

Just to clarify: I'm not asking you to actually implement this, I will try to do it once I find the time.

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: codeRelated to content of the project itselftype: enhancementProposed improvement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions