[TIPS] uTasker USB HID Keyboard State Detection

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

[TIPS] uTasker USB HID Keyboard State Detection

746 次查看
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 

标记 (5)
0 项奖励
回复
2 回复数

628 次查看
alresarena
Contributor III

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

0 项奖励
回复

628 次查看
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