Skip to content

Commit

Permalink
Added MOUSE_X1 and MOUSE_X2 buttons to mouse listener (see #20)
Browse files Browse the repository at this point in the history
  • Loading branch information
kristian committed Feb 9, 2019
1 parent 54d3f17 commit 5c620a6
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ You can include `system-hook` from this GitHub repository by adding this depende
<dependency>
<groupId>lc.kra.system</groupId>
<artifactId>system-hook</artifactId>
<version>3.2</version>
<version>3.3</version>
</dependency>
```

Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: 3.2.{build}
version: 3.3.{build}

branches:
only:
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>lc.kra.system</groupId>
<artifactId>system-hook</artifactId>
<version>3.2</version>
<version>3.3</version>
<description>Global Keyboard / Mouse Hook for Java applications.</description>
<url>https://github.com/kristian/system-hook</url>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down
24 changes: 23 additions & 1 deletion src/main/native/windows/SystemHook.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <jni.h>

#ifdef DEBUG
#include <stdio.h>
#define DEBUG_PRINT(x) do{ printf x; fflush(stdout); } while(0)
#else
#define DEBUG_PRINT(x) do{ } while(0)
Expand All @@ -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();
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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],
Expand Down

0 comments on commit 5c620a6

Please sign in to comment.