JNA - 读取多个按键

时间:2017-07-04 20:22:55

标签: java windows winapi jna

我的程序安装其他组件时,我使用JNA来阻止键盘。我想创建一个转义键组合,如CTRL + SHIFT + KEY。

如何检查这三个键是否被按下?当我检查info.vkCode一个单键时,它可以正常工作......

new Thread(new Runnable() {
    @Override
    public void run() {
        lib = User32.INSTANCE;
        HMODULE hMod = Kernel32.INSTANCE.GetModuleHandle(null);
        keyboardHook = new LowLevelKeyboardProc() {
        @Override
        public LRESULT callback(int nCode, WPARAM wParam, KBDLLHOOKSTRUCT info) {
            if (nCode >= 0) {
                //CTRL + SHIFT + F12, for example --- ERROR 
                if (info.vkCode == 160 && info.vkCode == 162 && info.vkCode == 123) {
                    lib.UnhookWindowsHookEx(hhk);
                }
                else {
                    return new LRESULT(1);
                }
            }
                return lib.CallNextHookEx(hhk, nCode, wParam, null);
            }
        };
        hhk = lib.SetWindowsHookEx(13, keyboardHook, hMod, 0);

        int result;
        MSG msg = new MSG();
        while ((result = lib.GetMessage(msg, null, 0, 0)) != 0) {
            if (result == -1) {
                break;
            }
            else {
                lib.TranslateMessage(msg);
                lib.DispatchMessage(msg);
            }
        }
        lib.UnhookWindowsHookEx(hhk);
    }
}).start();

1 个答案:

答案 0 :(得分:0)

lib.GetAsyncKeyState(VK_LCONTROL)