Keyboard
Keyboard copied to clipboard
Adding support for getting numlock/capslock/scrolllock states
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.
@per1234 I see you added the enhancement tag, but I wasn't making a feature request, I was asking if we could agree on how this feature would be implemented so that we can keep compatibility between our libraries.
Are you telling me you wouldn't consider that to be an enhancement?
There are three issue types: enhancement, bug, and invalid.
Sorry, I thought there were 7 types. I was thinking it would be a better fit for question or help wanted, but it doesn't really matter to me, I was just making sure that we don't have a misunderstanding. ;)
Related proposal: https://github.com/arduino-libraries/Keyboard/pull/61 Related request: https://github.com/arduino-libraries/Keyboard/issues/40
Excuse me, what's the progress now? Has the problem been solved?