本文整理汇总了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();
}