[TIPS] uTasker USB HID Keyboard State Detection

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

[TIPS] uTasker USB HID Keyboard State Detection

1,301件の閲覧回数
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 件の賞賛
返信
2 返答(返信)

1,183件の閲覧回数
alresarena
Contributor III

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

0 件の賞賛
返信

1,183件の閲覧回数
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