本文整理匯總了Java中com.sun.jna.platform.win32.WinUser.HOOKPROC類的典型用法代碼示例。如果您正苦於以下問題:Java HOOKPROC類的具體用法?Java HOOKPROC怎麽用?Java HOOKPROC使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
HOOKPROC類屬於com.sun.jna.platform.win32.WinUser包,在下文中一共展示了HOOKPROC類的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: main
import com.sun.jna.platform.win32.WinUser.HOOKPROC; //導入依賴的package包/類
public static void main(String[] args) throws Exception {
HOOKPROC hookProc = new HOOKPROC_bg();
HINSTANCE hInst = Kernel32.INSTANCE.GetModuleHandle(null);
User32.HHOOK hHook = User32.INSTANCE.SetWindowsHookEx(User32.WH_KEYBOARD_LL, hookProc, hInst, 0);
if (hHook == null)
return;
User32.MSG msg = new User32.MSG();
System.err.println("Please press any key ....");
while (true) {
User32.INSTANCE.GetMessage(msg, null, 0, 0);
}
}
示例2: registerMouseUpListner
import com.sun.jna.platform.win32.WinUser.HOOKPROC; //導入依賴的package包/類
public synchronized void registerMouseUpListner(Runnable action,
Executor executor)
{
if (thrd != null)
return;
this.action = action;
thrd = new Thread(new Runnable()
{
public void run()
{
try
{
if (!isHooked)
{
hhk = USER32INST.SetWindowsHookEx(14,
(HOOKPROC) mouseHook,
KERNEL32INST.GetModuleHandle(null), 0);
isHooked = true;
MSG msg = new MSG();
while ((USER32INST.GetMessage(msg, null, 0, 0)) != 0)
{
System.out.println("got message");
USER32INST.TranslateMessage(msg);
USER32INST.DispatchMessage(msg);
System.out.print(isHooked);
if (!isHooked)
break;
}
}
else
System.out.println("The Hook is already installed.");
}
catch (Exception e)
{
System.err.println(e.getMessage());
System.err.println("Caught exception in MouseHook!");
}
// System.out.println("terminated ");
USER32INST.UnhookWindowsHookEx(hhk);
hhk = null;
}
}, "Named thread");
threadFinish = false;
thrd.start();
}