diff --git a/docs/feature_mouse_keys.md b/docs/feature_mouse_keys.md index 8e2a3a4cd1..a0d02416f2 100644 --- a/docs/feature_mouse_keys.md +++ b/docs/feature_mouse_keys.md @@ -29,9 +29,6 @@ In your keymap you can use the following keycodes to map key presses to mouse ac |`KC_MS_BTN3` |`KC_BTN3`|Press button 3 | |`KC_MS_BTN4` |`KC_BTN4`|Press button 4 | |`KC_MS_BTN5` |`KC_BTN5`|Press button 5 | -|`KC_MS_BTN6` |`KC_BTN6`|Press button 6 | -|`KC_MS_BTN7` |`KC_BTN7`|Press button 7 | -|`KC_MS_BTN8` |`KC_BTN8`|Press button 8 | |`KC_MS_WH_UP` |`KC_WH_U`|Move wheel up | |`KC_MS_WH_DOWN` |`KC_WH_D`|Move wheel down | |`KC_MS_WH_LEFT` |`KC_WH_L`|Move wheel left | diff --git a/docs/feature_pointing_device.md b/docs/feature_pointing_device.md index 905c2a8f95..37edac5e6b 100644 --- a/docs/feature_pointing_device.md +++ b/docs/feature_pointing_device.md @@ -19,7 +19,7 @@ Keep in mind that a report_mouse_t (here "mouseReport") has the following proper * `mouseReport.y` - this is a signed int from -127 to 127 (not 128, this is defined in USB HID spec) representing movement (+ upward, - downward) on the y axis. * `mouseReport.v` - this is a signed int from -127 to 127 (not 128, this is defined in USB HID spec) representing vertical scrolling (+ upward, - downward). * `mouseReport.h` - this is a signed int from -127 to 127 (not 128, this is defined in USB HID spec) representing horizontal scrolling (+ right, - left). -* `mouseReport.buttons` - this is a uint8_t in which all 8 bits are used. These bits represent the mouse button state - bit 0 is mouse button 1, and bit 7 is mouse button 8. +* `mouseReport.buttons` - this is a uint8_t in which the last 5 bits are used. These bits represent the mouse button state - bit 3 is mouse button 5, and bit 7 is mouse button 1. Once you have made the necessary changes to the mouse report, you need to send it: diff --git a/docs/ja/feature_mouse_keys.md b/docs/ja/feature_mouse_keys.md index e4fa9dfb45..74b09e939b 100644 --- a/docs/ja/feature_mouse_keys.md +++ b/docs/ja/feature_mouse_keys.md @@ -34,9 +34,6 @@ MOUSEKEY_ENABLE = yes | `KC_MS_BTN3` | `KC_BTN3` | ボタン3を押す | | `KC_MS_BTN4` | `KC_BTN4` | ボタン4を押す | | `KC_MS_BTN5` | `KC_BTN5` | ボタン5を押す | -| `KC_MS_BTN6` | `KC_BTN6` | ボタン6を押す | -| `KC_MS_BTN7` | `KC_BTN7` | ボタン7を押す | -| `KC_MS_BTN8` | `KC_BTN8` | ボタン8を押す | | `KC_MS_WH_UP` | `KC_WH_U` | ホイールを向こう側に回転 | | `KC_MS_WH_DOWN` | `KC_WH_D` | ホイールを手前側に回転 | | `KC_MS_WH_LEFT` | `KC_WH_L` | ホイールを左に倒す | diff --git a/quantum/mousekey.c b/quantum/mousekey.c index 63e74baa93..1f2f6fefd7 100644 --- a/quantum/mousekey.c +++ b/quantum/mousekey.c @@ -278,8 +278,16 @@ void mousekey_on(uint8_t code) { mouse_report.h = wheel_unit() * -1; else if (code == KC_MS_WH_RIGHT) mouse_report.h = wheel_unit(); - else if (IS_MOUSEKEY_BUTTON(code)) - mouse_report.buttons |= 1 << (code - KC_MS_BTN1); + else if (code == KC_MS_BTN1) + mouse_report.buttons |= MOUSE_BTN1; + else if (code == KC_MS_BTN2) + mouse_report.buttons |= MOUSE_BTN2; + else if (code == KC_MS_BTN3) + mouse_report.buttons |= MOUSE_BTN3; + else if (code == KC_MS_BTN4) + mouse_report.buttons |= MOUSE_BTN4; + else if (code == KC_MS_BTN5) + mouse_report.buttons |= MOUSE_BTN5; else if (code == KC_MS_ACCEL0) mousekey_accel |= (1 << 0); else if (code == KC_MS_ACCEL1) @@ -305,8 +313,16 @@ void mousekey_off(uint8_t code) { mouse_report.h = 0; else if (code == KC_MS_WH_RIGHT && mouse_report.h > 0) mouse_report.h = 0; - else if (IS_MOUSEKEY_BUTTON(code)) - mouse_report.buttons &= ~(1 << (code - KC_MS_BTN1)); + else if (code == KC_MS_BTN1) + mouse_report.buttons &= ~MOUSE_BTN1; + else if (code == KC_MS_BTN2) + mouse_report.buttons &= ~MOUSE_BTN2; + else if (code == KC_MS_BTN3) + mouse_report.buttons &= ~MOUSE_BTN3; + else if (code == KC_MS_BTN4) + mouse_report.buttons &= ~MOUSE_BTN4; + else if (code == KC_MS_BTN5) + mouse_report.buttons &= ~MOUSE_BTN5; else if (code == KC_MS_ACCEL0) mousekey_accel &= ~(1 << 0); else if (code == KC_MS_ACCEL1) @@ -407,8 +423,16 @@ void mousekey_on(uint8_t code) { mouse_report.h = w_offset * -1; else if (code == KC_MS_WH_RIGHT) mouse_report.h = w_offset; - else if (IS_MOUSEKEY_BUTTON(code)) - mouse_report.buttons |= 1 << (code - KC_MS_BTN1); + else if (code == KC_MS_BTN1) + mouse_report.buttons |= MOUSE_BTN1; + else if (code == KC_MS_BTN2) + mouse_report.buttons |= MOUSE_BTN2; + else if (code == KC_MS_BTN3) + mouse_report.buttons |= MOUSE_BTN3; + else if (code == KC_MS_BTN4) + mouse_report.buttons |= MOUSE_BTN4; + else if (code == KC_MS_BTN5) + mouse_report.buttons |= MOUSE_BTN5; else if (code == KC_MS_ACCEL0) mk_speed = mkspd_0; else if (code == KC_MS_ACCEL1) @@ -438,8 +462,16 @@ void mousekey_off(uint8_t code) { mouse_report.h = 0; else if (code == KC_MS_WH_RIGHT && mouse_report.h > 0) mouse_report.h = 0; - else if (IS_MOUSEKEY_BUTTON(code)) - mouse_report.buttons &= ~(1 << (code - KC_MS_BTN1)); + else if (code == KC_MS_BTN1) + mouse_report.buttons &= ~MOUSE_BTN1; + else if (code == KC_MS_BTN2) + mouse_report.buttons &= ~MOUSE_BTN2; + else if (code == KC_MS_BTN3) + mouse_report.buttons &= ~MOUSE_BTN3; + else if (code == KC_MS_BTN4) + mouse_report.buttons &= ~MOUSE_BTN4; + else if (code == KC_MS_BTN5) + mouse_report.buttons &= ~MOUSE_BTN5; # ifdef MK_MOMENTARY_ACCEL else if (code == KC_MS_ACCEL0) mk_speed = mkspd_DEFAULT; diff --git a/tmk_core/common/action.c b/tmk_core/common/action.c index aae5cbfa5f..18e7b38da3 100644 --- a/tmk_core/common/action.c +++ b/tmk_core/common/action.c @@ -410,18 +410,52 @@ void process_action(keyrecord_t *record, action_t action) { case ACT_MOUSEKEY: if (event.pressed) { mousekey_on(action.key.code); + switch (action.key.code) { +# if defined(PS2_MOUSE_ENABLE) || defined(POINTING_DEVICE_ENABLE) + case KC_MS_BTN1: + register_button(true, MOUSE_BTN1); + break; + case KC_MS_BTN2: + register_button(true, MOUSE_BTN2); + break; + case KC_MS_BTN3: + register_button(true, MOUSE_BTN3); + break; +# endif +# ifdef POINTING_DEVICE_ENABLE + case KC_MS_BTN4: + register_button(true, MOUSE_BTN4); + break; + case KC_MS_BTN5: + register_button(true, MOUSE_BTN5); + break; +# endif + default: + mousekey_send(); + break; + } } else { mousekey_off(action.key.code); } switch (action.key.code) { # if defined(PS2_MOUSE_ENABLE) || defined(POINTING_DEVICE_ENABLE) -# ifdef POINTING_DEVICE_ENABLE - case KC_MS_BTN1 ... KC_MS_BTN8: -# else - case KC_MS_BTN1 ... KC_MS_BTN3: -# endif - register_button(event.pressed, MOUSE_BTN_MASK(action.key.code - KC_MS_BTN1)); - break; + case KC_MS_BTN1: + register_button(false, MOUSE_BTN1); + break; + case KC_MS_BTN2: + register_button(false, MOUSE_BTN2); + break; + case KC_MS_BTN3: + register_button(false, MOUSE_BTN3); + break; +# endif +# ifdef POINTING_DEVICE_ENABLE + case KC_MS_BTN4: + register_button(false, MOUSE_BTN4); + break; + case KC_MS_BTN5: + register_button(false, MOUSE_BTN5); + break; # endif default: mousekey_send(); diff --git a/tmk_core/common/keycode.h b/tmk_core/common/keycode.h index efad92b235..d35e44d8dc 100644 --- a/tmk_core/common/keycode.h +++ b/tmk_core/common/keycode.h @@ -39,7 +39,7 @@ along with this program. If not, see . #define IS_MOUSEKEY(code) (KC_MS_UP <= (code) && (code) <= KC_MS_ACCEL2) #define IS_MOUSEKEY_MOVE(code) (KC_MS_UP <= (code) && (code) <= KC_MS_RIGHT) -#define IS_MOUSEKEY_BUTTON(code) (KC_MS_BTN1 <= (code) && (code) <= KC_MS_BTN8) +#define IS_MOUSEKEY_BUTTON(code) (KC_MS_BTN1 <= (code) && (code) <= KC_MS_BTN5) #define IS_MOUSEKEY_WHEEL(code) (KC_MS_WH_UP <= (code) && (code) <= KC_MS_WH_RIGHT) #define IS_MOUSEKEY_ACCEL(code) (KC_MS_ACCEL0 <= (code) && (code) <= KC_MS_ACCEL2) @@ -205,9 +205,6 @@ along with this program. If not, see . #define KC_BTN3 KC_MS_BTN3 #define KC_BTN4 KC_MS_BTN4 #define KC_BTN5 KC_MS_BTN5 -#define KC_BTN6 KC_MS_BTN6 -#define KC_BTN7 KC_MS_BTN7 -#define KC_BTN8 KC_MS_BTN8 #define KC_WH_U KC_MS_WH_UP #define KC_WH_D KC_MS_WH_DOWN #define KC_WH_L KC_MS_WH_LEFT @@ -524,18 +521,15 @@ enum internal_special_keycodes { enum mouse_keys { /* Mouse Buttons */ - KC_MS_UP = 0xED, + KC_MS_UP = 0xF0, KC_MS_DOWN, KC_MS_LEFT, - KC_MS_RIGHT, // 0xF0 + KC_MS_RIGHT, KC_MS_BTN1, KC_MS_BTN2, KC_MS_BTN3, KC_MS_BTN4, KC_MS_BTN5, - KC_MS_BTN6, - KC_MS_BTN7, - KC_MS_BTN8, /* Mouse Wheel */ KC_MS_WH_UP, @@ -546,5 +540,5 @@ enum mouse_keys { /* Acceleration */ KC_MS_ACCEL0, KC_MS_ACCEL1, - KC_MS_ACCEL2 // 0xFF + KC_MS_ACCEL2 }; diff --git a/tmk_core/common/report.h b/tmk_core/common/report.h index 606a259643..2032536c31 100644 --- a/tmk_core/common/report.h +++ b/tmk_core/common/report.h @@ -36,14 +36,11 @@ enum hid_report_ids { /* Mouse buttons */ #define MOUSE_BTN_MASK(n) (1 << (n)) enum mouse_buttons { - MOUSE_BTN1 = MOUSE_BTN_MASK(0), - MOUSE_BTN2 = MOUSE_BTN_MASK(1), - MOUSE_BTN3 = MOUSE_BTN_MASK(2), - MOUSE_BTN4 = MOUSE_BTN_MASK(3), - MOUSE_BTN5 = MOUSE_BTN_MASK(4), - MOUSE_BTN6 = MOUSE_BTN_MASK(5), - MOUSE_BTN7 = MOUSE_BTN_MASK(6), - MOUSE_BTN8 = MOUSE_BTN_MASK(7) + MOUSE_BTN1 = (1 << 0), + MOUSE_BTN2 = (1 << 1), + MOUSE_BTN3 = (1 << 2), + MOUSE_BTN4 = (1 << 3), + MOUSE_BTN5 = (1 << 4) }; /* Consumer Page (0x0C) diff --git a/tmk_core/protocol/usb_descriptor.c b/tmk_core/protocol/usb_descriptor.c index a2020f5bb5..b028ff8c55 100644 --- a/tmk_core/protocol/usb_descriptor.c +++ b/tmk_core/protocol/usb_descriptor.c @@ -124,15 +124,19 @@ const USB_Descriptor_HIDReport_Datatype_t PROGMEM SharedReport[] = { # endif HID_RI_USAGE(8, 0x01), // Pointer HID_RI_COLLECTION(8, 0x00), // Physical - // Buttons (8 bits) + // Buttons (5 bits) HID_RI_USAGE_PAGE(8, 0x09), // Button HID_RI_USAGE_MINIMUM(8, 0x01), // Button 1 - HID_RI_USAGE_MAXIMUM(8, 0x08), // Button 8 + HID_RI_USAGE_MAXIMUM(8, 0x05), // Button 5 HID_RI_LOGICAL_MINIMUM(8, 0x00), HID_RI_LOGICAL_MAXIMUM(8, 0x01), - HID_RI_REPORT_COUNT(8, 0x08), + HID_RI_REPORT_COUNT(8, 0x05), HID_RI_REPORT_SIZE(8, 0x01), HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE), + // Button padding (3 bits) + HID_RI_REPORT_COUNT(8, 0x01), + HID_RI_REPORT_SIZE(8, 0x03), + HID_RI_INPUT(8, HID_IOF_CONSTANT), // X/Y position (2 bytes) HID_RI_USAGE_PAGE(8, 0x01), // Generic Desktop @@ -360,7 +364,7 @@ const USB_Descriptor_Device_t PROGMEM DeviceDescriptor = { .Type = DTYPE_Device }, .USBSpecification = VERSION_BCD(1, 1, 0), - + #if VIRTSER_ENABLE .Class = USB_CSCP_IADDeviceClass, .SubClass = USB_CSCP_IADDeviceSubclass, diff --git a/tmk_core/protocol/vusb/vusb.c b/tmk_core/protocol/vusb/vusb.c index e4e2a6faea..6da783e1fe 100644 --- a/tmk_core/protocol/vusb/vusb.c +++ b/tmk_core/protocol/vusb/vusb.c @@ -444,15 +444,19 @@ const PROGMEM uchar shared_hid_report[] = { 0x85, REPORT_ID_MOUSE, // Report ID 0x09, 0x01, // Usage (Pointer) 0xA1, 0x00, // Collection (Physical) - // Buttons (8 bits) + // Buttons (5 bits) 0x05, 0x09, // Usage Page (Button) 0x19, 0x01, // Usage Minimum (Button 1) - 0x29, 0x08, // Usage Maximum (Button 8) + 0x29, 0x05, // Usage Maximum (Button 5) 0x15, 0x00, // Logical Minimum (0) 0x25, 0x01, // Logical Maximum (1) - 0x95, 0x08, // Report Count (8) + 0x95, 0x05, // Report Count (5) 0x75, 0x01, // Report Size (1) 0x81, 0x02, // Input (Data, Variable, Absolute) + // Button padding (3 bits) + 0x95, 0x01, // Report Count (1) + 0x75, 0x03, // Report Size (3) + 0x81, 0x03, // Input (Constant) // X/Y position (2 bytes) 0x05, 0x01, // Usage Page (Generic Desktop)