From a648fd14e4b002b68e754e1981afb968f463dca6 Mon Sep 17 00:00:00 2001 From: newsdee Date: Mon, 29 Jun 2015 16:33:10 +0000 Subject: [PATCH] [FIRMWARE] joy2key: fixed handling of modifier keys --- usb/hid.c | 47 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 37 insertions(+), 10 deletions(-) diff --git a/usb/hid.c b/usb/hid.c index 3ad10a3..70be941 100644 --- a/usb/hid.c +++ b/usb/hid.c @@ -134,6 +134,7 @@ void virtual_joystick_remap(char *s) { static struct { uint16_t mask; + uint8_t modifier; uint8_t keys[6]; // support up to 6 key codes } joy_key_map[MAX_JOYSTICK_KEYBOARD_MAP]; @@ -145,7 +146,9 @@ void joy_key_map_init(void) { void joystick_key_map(char *s) { uint8_t i,j; uint8_t count; + uint8_t assign=0; uint8_t len = strlen(s); + uint8_t scancode=0; char *token; hid_debugf("%s(%s)", __FUNCTION__, s); @@ -159,6 +162,7 @@ void joystick_key_map(char *s) { for(i=0;i223) { + // bit 0 1 2 3 4 5 6 7 + // key LCTRL LSHIFT LALT LGUI RCTRL RSHIFT RALT RGUI + // + scancode -= 223; + joy_key_map[i].modifier |= (0x01 << (scancode-1)); + } else { + // max 6 keys + if (assign < 7) + joy_key_map[i].keys[assign++] = scancode; + } } s = strtok (NULL, ","); count+=1; @@ -712,6 +726,8 @@ static uint8_t usb_hid_poll(usb_device_t *dev) { hid_debugf("%s() error: %d", __FUNCTION__, rcode); } else { + uint8_t keyb_hit = 0; + // successfully received some bytes if(iface->has_boot_mode && !iface->ignore_boot_mode) { if(iface->device_type == HID_DEVICE_MOUSE) { @@ -723,8 +739,10 @@ static uint8_t usb_hid_poll(usb_device_t *dev) { if(iface->device_type == HID_DEVICE_KEYBOARD) { // boot kbd needs at least eight bytes - if(read >= 8) + if(read >= 8) { user_io_kbd(buf[0], buf+2); + if (buf[0]||buf[1]) keyb_hit=1; //declare keyboard as pressed for later overrides + } } } @@ -1026,7 +1044,7 @@ static uint8_t usb_hid_poll(usb_device_t *dev) { if(vjoy & JOY_B) buf[0] = 0x29; // ESC if(vjoy & JOY_START) buf[0] = 0x45; // F12 if(vjoy & JOY_LEFT) buf[0] = 0x50; // left arrow - if(vjoy & JOY_RIGHT) buf[0] = 0x49; // right arrow + if(vjoy & JOY_RIGHT) buf[0] = 0x4F; // right arrow // up and down uses SELECT or L for faster scrolling if(vjoy & JOY_UP) { if (vjoy & JOY_SELECT || vjoy & JOY_L) buf[1] = 0x4B; // page up @@ -1071,16 +1089,20 @@ static uint8_t usb_hid_poll(usb_device_t *dev) { // process mapped keyboard commands from mist.ini uint8_t i, j, count=0; + uint8_t mapped_hit = 0; + uint8_t modifier = 0; uint8_t joy_buf[6] = { 0,0,0,0,0,0 }; for(i=0;ikeyboard shortcuts