From 5c620a6b9a6b17c968c50e94fe50260e27f2e7d0 Mon Sep 17 00:00:00 2001 From: Kristian Kraljic Date: Sat, 9 Feb 2019 22:11:16 +0100 Subject: [PATCH] Added MOUSE_X1 and MOUSE_X2 buttons to mouse listener (see #20) --- README.md | 2 +- appveyor.yml | 2 +- pom.xml | 2 +- .../system/mouse/event/GlobalMouseEvent.java | 8 ++++++- src/main/native/windows/SystemHook.c | 24 ++++++++++++++++++- 5 files changed, 33 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index c7e6a2a..165c4d6 100644 --- a/README.md +++ b/README.md @@ -99,7 +99,7 @@ You can include `system-hook` from this GitHub repository by adding this depende lc.kra.system system-hook - 3.2 + 3.3 ``` diff --git a/appveyor.yml b/appveyor.yml index ddb3a18..21574cc 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,4 +1,4 @@ -version: 3.2.{build} +version: 3.3.{build} branches: only: diff --git a/pom.xml b/pom.xml index d983183..5f01aa4 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 lc.kra.system system-hook - 3.2 + 3.3 Global Keyboard / Mouse Hook for Java applications. https://github.com/kristian/system-hook diff --git a/src/main/java/lc/kra/system/mouse/event/GlobalMouseEvent.java b/src/main/java/lc/kra/system/mouse/event/GlobalMouseEvent.java index 5123742..080286d 100644 --- a/src/main/java/lc/kra/system/mouse/event/GlobalMouseEvent.java +++ b/src/main/java/lc/kra/system/mouse/event/GlobalMouseEvent.java @@ -41,7 +41,9 @@ public class GlobalMouseEvent extends EventObject { BUTTON_NO = 0x0, //No mouse button BUTTON_LEFT = 1<<0, //Left mouse button BUTTON_RIGHT = 1<<1, //Right mouse button - BUTTON_MIDDLE = 1<<4; //Middle mouse button + BUTTON_MIDDLE = 1<<4, //Middle mouse button + BUTTON_X1 = 1<<5, //First X mouse button + BUTTON_X2 = 1<<6; //Second X mouse button /** * Wheel delta parameter @@ -136,6 +138,10 @@ public GlobalMouseEvent(Object source, int transitionState, int button, int butt builder.append("right,"); if((buttons&BUTTON_MIDDLE)!=BUTTON_NO) builder.append("middle,"); + if((buttons&BUTTON_X1)!=BUTTON_NO) + builder.append("firstx,"); + if((buttons&BUTTON_X2)!=BUTTON_NO) + builder.append("secondx,"); if(transitionState==TS_WHEEL) builder.append("delta ").append(delta).append(','); return builder.deleteCharAt(builder.length()-1).append(']').toString(); diff --git a/src/main/native/windows/SystemHook.c b/src/main/native/windows/SystemHook.c index b3e83a8..d39a1e0 100644 --- a/src/main/native/windows/SystemHook.c +++ b/src/main/native/windows/SystemHook.c @@ -25,6 +25,7 @@ #include #ifdef DEBUG +#include #define DEBUG_PRINT(x) do{ printf x; fflush(stdout); } while(0) #else #define DEBUG_PRINT(x) do{ } while(0) @@ -40,7 +41,9 @@ extern "C" const LPCSTR lpszClassNames[] = { "jkh" /* java keyboard hook */, "jmh" /* java mouse hook */ }; const USHORT mouseLeftButton = RI_MOUSE_LEFT_BUTTON_DOWN|RI_MOUSE_LEFT_BUTTON_UP, mouseRightButton = RI_MOUSE_RIGHT_BUTTON_DOWN|RI_MOUSE_RIGHT_BUTTON_UP, - mouseMiddleButton = RI_MOUSE_MIDDLE_BUTTON_DOWN|RI_MOUSE_MIDDLE_BUTTON_UP; + mouseMiddleButton = RI_MOUSE_MIDDLE_BUTTON_DOWN|RI_MOUSE_MIDDLE_BUTTON_UP, + mouseXButton1 = RI_MOUSE_BUTTON_4_DOWN|RI_MOUSE_BUTTON_4_UP, + mouseXButton2 = RI_MOUSE_BUTTON_5_DOWN|RI_MOUSE_BUTTON_5_UP; static inline void debugPrintLastError(TCHAR *szErrorText) { DWORD dw = GetLastError(); @@ -135,6 +138,17 @@ LRESULT CALLBACK LowLevelMouseProc(int nCode, WPARAM wParam, LPARAM lParam) { case WM_MBUTTONUP: mkButton = MK_MBUTTON; break; + case WM_XBUTTONDOWN: + tState = (jint)TS_DOWN; + /* no break */ + case WM_XBUTTONUP: { + int button = pStruct->mouseData >> 16 & 0xFFFF; + if (button == 1) + mkButton += MK_XBUTTON1; + else if (button == 2) + mkButton += MK_XBUTTON2; + break; + } case WM_MOUSEMOVE: tState = (jint)TS_MOVE; if(lPosX!=lOldX||lOldX!=lOldY) @@ -228,6 +242,14 @@ LRESULT CALLBACK WndProc(HWND hWndMain, UINT uMsg, WPARAM wParam, LPARAM lParam) mkButton = MK_MBUTTON; if((buttonFlags&RI_MOUSE_MIDDLE_BUTTON_DOWN)==RI_MOUSE_MIDDLE_BUTTON_DOWN) tState = (jint)TS_DOWN; + } else if((buttonFlags&mouseXButton1)!=0) { + mkButton = MK_XBUTTON1; + if((buttonFlags&RI_MOUSE_BUTTON_4_DOWN)==RI_MOUSE_BUTTON_4_DOWN) + tState = (jint)TS_DOWN; + } else if((buttonFlags&mouseXButton2)!=0) { + mkButton = MK_XBUTTON2; + if((buttonFlags&RI_MOUSE_BUTTON_5_DOWN)==RI_MOUSE_BUTTON_5_DOWN) + tState = (jint)TS_DOWN; } // handle mouse buttons if(mkButton!=0) (*env)->CallVoidMethod(env, hookObj[HOOK_MOUSE], handleMeth[HOOK_MOUSE],