我不知道JNA解决方案,但是有一个完善的全局热键库,称为JIntelliType
编辑:此问题的正确答案是使用GetMessage而不是MsgWaitForMultipleObjects。我使用BridJ编写了一个简单的示例,它很好用:
if (!RegisterHotKey(null, id, MOD_ALT | MOD_NOREPEAT, 0x42)) { System.out.println("Error"); return; } Pointer<MSG> msgPointer = Pointer.allocate(MSG.class); try { while (GetMessage(msgPointer, null, 0, 0) != 0) { MSG msg = msgPointer.get(); if (msg.message() == WM_HOTKEY && msg.wParam() == id) { System.out.println("YEAH"); } } } catch (Exception e) { e.printStackTrace(); } finally { UnregisterHotKey(null, id); }


