Skip to content

Commit

Permalink
Fix bug in native module for raw input
Browse files Browse the repository at this point in the history
  • Loading branch information
kristian committed Oct 18, 2020
1 parent ecac4d1 commit c946389
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ You can include `system-hook` as a dependency from Maven Central by adding it to
<dependency>
<groupId>lc.kra.system</groupId>
<artifactId>system-hook</artifactId>
<version>3.7</version>
<version>3.8</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.7.{build}
version: 3.8.{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 @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>lc.kra.system</groupId>
<artifactId>system-hook</artifactId>
<version>3.7</version>
<version>3.8</version>

<name>Java System Hook</name>
<description>Global Keyboard / Mouse Hook for Java applications.</description>
Expand Down
18 changes: 15 additions & 3 deletions src/main/native/windows/SystemHook.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,6 @@ LRESULT CALLBACK WndProc(HWND hWndMain, UINT uMsg, WPARAM wParam, LPARAM lParam)
UINT event = raw->data.keyboard.Message;
USHORT vkCode = raw->data.keyboard.VKey,
scanCode = raw->data.keyboard.MakeCode;
free(lpb); // free this now to save memory

handleKey("WndProc", event, vkCode, scanCode, hDevice);

Expand All @@ -225,7 +224,6 @@ LRESULT CALLBACK WndProc(HWND hWndMain, UINT uMsg, WPARAM wParam, LPARAM lParam)
case RIM_TYPEMOUSE: {
LONG lLastX = raw->data.mouse.lLastX, lLastY = raw->data.mouse.lLastY;
USHORT buttonFlags = raw->data.mouse.usButtonFlags, buttonData = raw->data.mouse.usButtonData;
free(lpb); // free this now to save memory

JNIEnv* env;
if((*jvm)->AttachCurrentThread(jvm, (void**)&env, NULL)>=JNI_OK) {
Expand Down Expand Up @@ -267,11 +265,25 @@ LRESULT CALLBACK WndProc(HWND hWndMain, UINT uMsg, WPARAM wParam, LPARAM lParam)
break;
}
}

DefRawInputProc(&raw, 1, sizeof(RAWINPUTHEADER));
free(lpb); // free this now to save memory

break;
}
case WM_CLOSE:
case WM_CLOSE: {
// determine the hook window (by the hWndMain)
size_t hook = SHRT_MAX; for(size_t ridIdx=0;ridIdx<sizeof(rid)/sizeof(rid[0]);ridIdx++)
if(rid[ridIdx].hwndTarget == hWndMain)
{ hook = ridIdx; break; }
if(hook==SHRT_MAX) return FALSE; // unknown hook

rid[hook].dwFlags = RIDEV_REMOVE;
RegisterRawInputDevices(&rid[hook], 1, sizeof(rid[hook]));

PostQuitMessage(0);
break;
}
default:
return DefWindowProc(hWndMain, uMsg, wParam, lParam);
}
Expand Down

0 comments on commit c946389

Please sign in to comment.