[TIPS] uTasker USB HID Keyboard State Detection
usb_application.c :
static unsigned char ucLockKeys = 0;
#define NUM_LOCK_FLAG 0x01
#define CAPS_LOCK_FLAG 0x02
#define SCROLL_LOCK_FLAG 0x04
#define LOCK_KEYS (NUM_LOCK_FLAG | CAPS_LOCK_FLAG | SCROLL_LOCK_FLAG)
static void fnSetKeyboardOutput(unsigned char ucOutputs) // assumed to be set report with a single byte content
{
// Directly change the state of outputs
//
ucLockKeys = (ucOutputs & LOCK_KEYS); // present lock key states
}
Credits by: Mark Butcher
Thank you so much Sir Mark:smileyhappy: .. I'll try your code because it looks cleaner and efficient.
Hi Alres
I am pleased to see that you are progressing with your HID Keyboard work!
Could you consider doing the following to be more efficient? The present state of each lock key is then kept locally as a flag in a byte.
static unsigned char ucLockKeys = 0;
#define NUM_LOCK_FLAG 0x01
#define CAPS_LOCK_FLAG 0x02
#define SCROLL_LOCK_FLAG 0x04
#define LOCK_KEYS (NUM_LOCK_FLAG | CAPS_LOCK_FLAG | SCROLL_LOCK_FLAG)
static void fnSetKeyboardOutput(unsigned char ucOutputs) // assumed to be set report with a single byte content
{
// Directly change the state of outputs
//
ucLockKeys = (ucOutputs & LOCK_KEYS); // present lock key states
}
Regards
Mark