send keys over WebSocket

This commit is contained in:
2025-07-20 17:38:02 -04:00
parent d25218898b
commit f628003c66
12 changed files with 1688 additions and 1127 deletions
+33 -26
View File
@@ -13,9 +13,7 @@ void parse_key_list(char * keys) {
uint8_t keypos = 2; // bytes 2-7 are used for normal keys
uint8_t code = 0x00;
static unsigned char boot_report[8];
static unsigned char mouse_report[3];
memset(boot_report, 0x00, 8);
memset(mouse_report, 0x00, 3);
// Javascript sends the list as comma delimited, so split into individual
// keys by splitting at commas
@@ -29,41 +27,18 @@ void parse_key_list(char * keys) {
keypos++;
}
// if a scan code was not returned, it might be a modifier or mouse
// if a scan code was not returned, it might be a modifier
if (code == 0x00) {
// search for the correct modifier bit and add it to byte 0 of the
// USB boot keyboard report
code = parse_mod(token);
if (code) {
boot_report[0] = boot_report[0] | code;
} else if ( strncmp(&token[0],"Mouse", 5) == 0 ){
if ( strncmp(&token[5], "Left", 4) == 0 ) {
mouse_report[1] = -1*MOUSE_SPEED;
} else if ( strncmp(&token[5], "Right", 5) == 0 ) {
mouse_report[1] = 1*MOUSE_SPEED;
} else if ( strncmp(&token[5], "Up", 2) == 0 ) {
mouse_report[2] = -1*MOUSE_SPEED;
} else if ( strncmp(&token[5], "Down", 4) == 0 ) {
mouse_report[2] = 1*MOUSE_SPEED;
} else if ( strncmp(&token[5], "ClickLeft", 9) == 0 ) {
mouse_report[0] = mouse_report[0] | 1;
} else if ( strncmp(&token[5], "ClickRight", 10) == 0) {
mouse_report[0] = mouse_report[0] | 2;
}
}
}
token = strtok(NULL, ",");
}
// print resulting HID boot mouse report to CDC for debugging
printf("Mouse report: ");
for(int i=0; i<3; i++){
printf("%02X ",mouse_report[i]);
}
printf("\n");
tud_hid_report(REPORT_ID_MOUSE, mouse_report, 3);
// print resulting HID boot keyboard report to CDC for debugging
printf("Keyboard report: ");
for(int i=0; i<8; i++){
@@ -74,6 +49,38 @@ void parse_key_list(char * keys) {
tud_hid_report(REPORT_ID_KEYBOARD, boot_report, 8);
}
void parse_mouse_list (char * keys) {
static unsigned char mouse_report[3];
memset(mouse_report, 0x00, 3);
// Javascript sends the list as comma delimited, so split into individual
// keys by splitting at commas
char * token = strtok(keys, ",");
while (token != NULL) {
if ( strncmp(&token[0],"MouseLeft", 9) == 0 ){
mouse_report[1] = -1*MOUSE_SPEED;
} else if ( strncmp(&token[0], "MouseRight", 10) == 0 ) {
mouse_report[1] = 1*MOUSE_SPEED;
} else if ( strncmp(&token[0], "MouseUp", 7) == 0 ) {
mouse_report[2] = -1*MOUSE_SPEED;
} else if ( strncmp(&token[0], "MouseDown", 9) == 0 ) {
mouse_report[2] = 1*MOUSE_SPEED;
} else if ( strncmp(&token[0], "MouseClickLeft", 14) == 0 ) {
mouse_report[0] = mouse_report[0] | 1;
} else if ( strncmp(&token[0], "MouseClickRight", 15) == 0) {
mouse_report[0] = mouse_report[0] | 2;
}
token = strtok(NULL, ",");
}
// print resulting HID boot mouse report to CDC for debugging
printf("Mouse report: ");
for(int i=0; i<3; i++){
printf("%02X ",mouse_report[i]);
}
printf("\n");
tud_hid_report(REPORT_ID_MOUSE, mouse_report, 3);
}
// take a single Javascript key code and convert it to USB HID scancode
// if it is a regular key, i.e. not a modifier key