[TIPS] uTasker USB HID Keyboard State Detection

cancel
Showing results for 
Search instead for 
Did you mean: 

[TIPS] uTasker USB HID Keyboard State Detection

267 Views
alresarena
Contributor III

[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 

0 Kudos
2 Replies

149 Views
alresarena
Contributor III

Thank you so much Sir Mark:smileyhappy: .. I'll try your code because it looks cleaner and efficient.

0 Kudos

149 Views
mjbcswitzerland
Specialist V

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