环境:window11 vscode
版本库:v5.0-rc1*
芯片:ESP32-S3
请问在这个例程中,连接window10电脑,要如何获取CapsLock、Numlock键的状态。就是当window上的 CapsLock、Numlock键状态改变时,芯片也可以及时获取到最新的CapsLock、Numlock状态。
如果能帮忙解决,非常感谢!
请教关于蓝牙键盘例程,如何获取CapsLock键的状态?
Re: 请教关于蓝牙键盘例程,如何获取CapsLock键的状态?
Code: Select all
void tud_hid_set_report_cb(uint8_t instance, uint8_t report_id, hid_report_type_t report_type, uint8_t const *buffer, uint16_t bufsize)
{
(void)report_id;
// keyboard interface
if (instance == ITF_NUM_KEYBOARD)
{
// Set keyboard LED e.g Capslock, Numlock etc...
if (report_type == HID_REPORT_TYPE_OUTPUT)
{
// bufsize should be (at least) 1
if (bufsize < 1)
return;
uint8_t const kbd_leds = buffer[0];
// Cap_lock = 0;
if (kbd_leds & KEYBOARD_LED_CAPSLOCK)
{
// Capslock On: disable blink, turn led on
if (Cap_lock == false)
ESP_LOGI(TAG, "Capslock On");
Cap_lock = true;
}
else
{
// Caplocks Off: back to normal blink
if (Cap_lock == true)
ESP_LOGI(TAG, "Caplocks Off");
Cap_lock = false;
}
if (kbd_leds & KEYBOARD_LED_NUMLOCK)
{
if (Num_Lock == false)
ESP_LOGI(TAG, "Numlock On");
Num_Lock = true;
}
else
{
if (Num_Lock == true)
ESP_LOGI(TAG, "Numlock Off");
Num_Lock = false;
}
if (kbd_leds & KEYBOARD_LED_SCROLLLOCK)
{
if (Scroll_Lock == false)
ESP_LOGI(TAG, "Scroll Lock On");
Scroll_Lock = true;
}
else
{
if (Scroll_Lock == true)
ESP_LOGI(TAG, "Scroll Lock Off");
Scroll_Lock = false;
}
if (kbd_leds & KEYBOARD_LED_COMPOSE)
{
if (Compos_Mode == false)
ESP_LOGI(TAG, "Composition Mode On");
Compos_Mode = true;
}
else
{
if (Compos_Mode == true)
ESP_LOGI(TAG, "Composition Mode Off");
Compos_Mode = false;
}
if (kbd_leds & KEYBOARD_LED_KANA)
{
if (kana_Mode == false)
ESP_LOGI(TAG, "Kana Mode On");
kana_Mode = true;
}
else
{
if (kana_Mode == true)
ESP_LOGI(TAG, "Kana Mode Off");
kana_Mode = false;
}
}
}
}
Who is online
Users browsing this forum: No registered users and 104 guests