자바 로 마우스 우 클릭 차단
1805 단어 jna
package com.xxx.proj.browser;
import com.sun.jna.platform.win32.Kernel32;
import com.sun.jna.platform.win32.User32;
import com.sun.jna.platform.win32.WinDef.HMODULE;
import com.sun.jna.platform.win32.WinDef.LRESULT;
import com.sun.jna.platform.win32.WinDef.WPARAM;
import com.sun.jna.platform.win32.WinUser;
public class MouseHook implements Runnable {
private WinUser.HHOOK hhk;
//
private WinUser.LowLevelKeyboardProc mouseProc = new WinUser.LowLevelKeyboardProc() {
@Override
public LRESULT callback(int nCode, WPARAM wParam, WinUser.KBDLLHOOKSTRUCT event) {
//
if (nCode >= 0) {
// System.out.println(wParam);
//
if (wParam.intValue() == 517 || wParam.intValue() == 516)
return new LRESULT(1);
}
return User32.INSTANCE.CallNextHookEx(hhk, nCode, wParam, null);
}
};
public void run() {
setHookOn();
}
//
public void setHookOn() {
System.out.println("Hook On!");
HMODULE hMod = Kernel32.INSTANCE.GetModuleHandle(null);
hhk = User32.INSTANCE.SetWindowsHookEx(User32.WH_MOUSE_LL, mouseProc, hMod, 0);
int result;
WinUser.MSG msg = new WinUser.MSG();
while ((result = User32.INSTANCE.GetMessage(msg, null, 0, 0)) != 0) {
if (result == -1) {
setHookOff();
break;
} else {
User32.INSTANCE.TranslateMessage(msg);
User32.INSTANCE.DispatchMessage(msg);
}
}
}
//
public void setHookOff() {
System.out.println("Hook Off!");
User32.INSTANCE.UnhookWindowsHookEx(hhk);
System.exit(0);
}
public static void main(String[] args) {
MouseHook kbhook = new MouseHook();
new Thread(kbhook).start();
}
}
원본 코드:https://download.csdn.net/download/aidy2008/10678219