diff --git a/converter/adb_usb/matrix.c b/converter/adb_usb/matrix.c
index 96c08f461d..2d4e8e9465 100644
--- a/converter/adb_usb/matrix.c
+++ b/converter/adb_usb/matrix.c
@@ -414,6 +414,11 @@ void adb_mouse_task(void)
return;
}
+
+uint8_t adb_mouse_buttons(void)
+{
+ return mouse_report.buttons;
+}
#endif
uint8_t matrix_scan(void)
diff --git a/converter/ibmpc_usb/ibmpc_usb.cpp b/converter/ibmpc_usb/ibmpc_usb.cpp
index cc91bb4305..89c3a71f57 100644
--- a/converter/ibmpc_usb/ibmpc_usb.cpp
+++ b/converter/ibmpc_usb/ibmpc_usb.cpp
@@ -85,6 +85,14 @@ action_t action_for_key(uint8_t layer, keypos_t key)
return (action_t){ .code = pgm_read_word(&actionmaps[(layer)][key.row & 0x07][key.col & 0x0F]) };
}
+#ifdef IBMPC_MOUSE_ENABLE
+static uint8_t last_buttons;
+uint8_t ibmpc_mouse_buttons(void)
+{
+ return last_buttons;
+}
+#endif
+
void IBMPCConverter::set_led(uint8_t usb_led)
{
@@ -607,6 +615,7 @@ uint8_t IBMPCConverter::process_interface(void)
mouse_report.v = -CHOP8(v);
mouse_report.h = CHOP8(h);
host_mouse_send(&mouse_report);
+ last_buttons = mouse_report.buttons;
xprintf("M[x:%d y:%d v:%d h:%d b:%02X]\n", mouse_report.x, mouse_report.y,
mouse_report.v, mouse_report.h, mouse_report.buttons);
break; }
diff --git a/converter/ibmpc_usb/ibmpc_usb.hpp b/converter/ibmpc_usb/ibmpc_usb.hpp
index 764052e5c7..9d924069df 100644
--- a/converter/ibmpc_usb/ibmpc_usb.hpp
+++ b/converter/ibmpc_usb/ibmpc_usb.hpp
@@ -16,6 +16,10 @@
#define ROW(code) ((code>>4)&0x07)
#define COL(code) (code&0x0F)
+#ifdef IBMPC_MOUSE_ENABLE
+extern "C" uint8_t ibmpc_mouse_buttons(void);
+#endif
+
class IBMPCConverter {
public:
diff --git a/tmk_core/common/host.c b/tmk_core/common/host.c
index 1f40aa49e6..b3095ad7c8 100644
--- a/tmk_core/common/host.c
+++ b/tmk_core/common/host.c
@@ -22,6 +22,22 @@ along with this program. If not, see .
#include "util.h"
#include "debug.h"
+#ifdef MOUSEKEY_ENABLE
+# include "mousekey.h"
+#endif
+#ifdef PS2_MOUSE_ENABLE
+# include "ps2_mouse.h"
+#endif
+#ifdef SERIAL_MOUSE_ENABLE
+# include "serial_mouse.h"
+#endif
+#ifdef ADB_MOUSE_ENABLE
+# include "adb.h"
+#endif
+#ifdef IBMPC_MOUSE_ENABLE
+uint8_t ibmpc_mouse_buttons(void);
+#endif
+
#if defined(NKRO_ENABLE) || defined(NKRO_6KRO_ENABLE)
bool keyboard_nkro = true;
@@ -70,7 +86,26 @@ void host_mouse_send(report_mouse_t *report)
report->boot_x = (report->x > 127) ? 127 : ((report->x < -127) ? -127 : report->x);
report->boot_y = (report->y > 127) ? 127 : ((report->y < -127) ? -127 : report->y);
#endif
+
+ /* Mouse buttons integration */
+ uint8_t b = report->buttons;
+#ifdef MOUSEKEY_ENABLE
+ report->buttons |= mousekey_buttons();
+#endif
+#ifdef PS2_MOUSE_ENABLE
+ report->buttons |= ps2_mouse_buttons();
+#endif
+#ifdef SERIAL_MOUSE_ENABLE
+ report->buttons |= serial_mouse_buttons();
+#endif
+#ifdef ADB_MOUSE_ENABLE
+ report->buttons |= adb_mouse_buttons();
+#endif
+#ifdef IBMPC_MOUSE_ENABLE
+ report->buttons |= ibmpc_mouse_buttons();
+#endif
(*driver->send_mouse)(report);
+ report->buttons = b;
}
void host_system_send(uint16_t report)
diff --git a/tmk_core/common/mousekey.c b/tmk_core/common/mousekey.c
index 23469476e2..8dfb6c1994 100644
--- a/tmk_core/common/mousekey.c
+++ b/tmk_core/common/mousekey.c
@@ -182,6 +182,11 @@ void mousekey_clear(void)
mousekey_accel = 0;
}
+uint8_t mousekey_buttons(void)
+{
+ return mouse_report.buttons;
+}
+
static void mousekey_debug(void)
{
if (!debug_mouse) return;
diff --git a/tmk_core/common/mousekey.h b/tmk_core/common/mousekey.h
index 6eede06b44..5b64acefe5 100644
--- a/tmk_core/common/mousekey.h
+++ b/tmk_core/common/mousekey.h
@@ -69,6 +69,7 @@ void mousekey_on(uint8_t code);
void mousekey_off(uint8_t code);
void mousekey_clear(void);
void mousekey_send(void);
+uint8_t mousekey_buttons(void);
#ifdef __cplusplus
}
diff --git a/tmk_core/protocol/adb.h b/tmk_core/protocol/adb.h
index 2e4c8f21b9..6e689e0320 100644
--- a/tmk_core/protocol/adb.h
+++ b/tmk_core/protocol/adb.h
@@ -109,6 +109,7 @@ void adb_host_reset_hard(void);
void adb_host_kbd_led(uint8_t addr, uint8_t led);
void adb_mouse_task(void);
void adb_mouse_init(void);
+uint8_t adb_mouse_buttons(void);
#endif
diff --git a/tmk_core/protocol/ps2_mouse.c b/tmk_core/protocol/ps2_mouse.c
index b0f77a83b0..4c0f02af62 100644
--- a/tmk_core/protocol/ps2_mouse.c
+++ b/tmk_core/protocol/ps2_mouse.c
@@ -28,6 +28,7 @@ along with this program. If not, see .
static report_mouse_t mouse_report = {};
+static uint8_t last_buttons;
static void print_usb_data(void);
@@ -161,6 +162,7 @@ void ps2_mouse_task(void)
host_mouse_send(&mouse_report);
+ last_buttons = mouse_report.buttons;
print_usb_data();
}
// clear report
@@ -171,6 +173,11 @@ void ps2_mouse_task(void)
mouse_report.buttons = 0;
}
+uint8_t ps2_mouse_buttons(void)
+{
+ return last_buttons;
+}
+
static void print_usb_data(void)
{
if (!debug_mouse) return;
diff --git a/tmk_core/protocol/ps2_mouse.h b/tmk_core/protocol/ps2_mouse.h
index 27d9790d43..d8d46a4984 100644
--- a/tmk_core/protocol/ps2_mouse.h
+++ b/tmk_core/protocol/ps2_mouse.h
@@ -62,5 +62,6 @@ along with this program. If not, see .
uint8_t ps2_mouse_init(void);
void ps2_mouse_task(void);
+uint8_t ps2_mouse_buttons(void);
#endif
diff --git a/tmk_core/protocol/serial_mouse.h b/tmk_core/protocol/serial_mouse.h
index 226314fc0e..e09d15c148 100644
--- a/tmk_core/protocol/serial_mouse.h
+++ b/tmk_core/protocol/serial_mouse.h
@@ -29,5 +29,6 @@ static inline uint8_t serial_mouse_init(void)
}
void serial_mouse_task(void);
+uint8_t serial_mouse_buttons(void);
#endif
diff --git a/tmk_core/protocol/serial_mouse_microsoft.c b/tmk_core/protocol/serial_mouse_microsoft.c
index ab74b7cdd3..8f5bceb7c7 100644
--- a/tmk_core/protocol/serial_mouse_microsoft.c
+++ b/tmk_core/protocol/serial_mouse_microsoft.c
@@ -32,6 +32,7 @@ along with this program. If not, see .
#endif
#define MAX(X, Y) ((X) > (Y) ? (X) : (Y))
+static uint8_t last_buttons;
static void print_usb_data(const report_mouse_t *report);
void serial_mouse_task(void)
@@ -71,6 +72,7 @@ void serial_mouse_task(void)
print_usb_data(&report);
host_mouse_send(&report);
+ last_buttons = report.buttons;
return;
}
@@ -111,6 +113,12 @@ void serial_mouse_task(void)
print_usb_data(&report);
host_mouse_send(&report);
+ last_buttons = report.buttons;
+}
+
+uint8_t serial_mouse_buttons(void)
+{
+ return last_buttons;
}
static void print_usb_data(const report_mouse_t *report)
diff --git a/tmk_core/protocol/serial_mouse_mousesystems.c b/tmk_core/protocol/serial_mouse_mousesystems.c
index cfe8996216..04fcc7b396 100644
--- a/tmk_core/protocol/serial_mouse_mousesystems.c
+++ b/tmk_core/protocol/serial_mouse_mousesystems.c
@@ -34,6 +34,7 @@ along with this program. If not, see .
//#define SERIAL_MOUSE_CENTER_SCROLL
+static uint8_t last_buttons;
static void print_usb_data(const report_mouse_t *report);
void serial_mouse_task(void)
@@ -78,6 +79,7 @@ void serial_mouse_task(void)
print_usb_data(&report);
host_mouse_send(&report);
+ last_buttons = report.buttons;
if (buffer[3] || buffer[4]) {
report.h = MAX((int8_t)buffer[3], -127);
@@ -85,6 +87,7 @@ void serial_mouse_task(void)
print_usb_data(&report);
host_mouse_send(&report);
+ last_buttons = report.buttons;
}
return;
@@ -117,9 +120,15 @@ void serial_mouse_task(void)
print_usb_data(&report);
host_mouse_send(&report);
+ last_buttons = report.buttons;
}
}
+uint8_t serial_mouse_buttons(void)
+{
+ return last_buttons;
+}
+
static void print_usb_data(const report_mouse_t *report)
{
if (!debug_mouse)