1
votes

I'm using JNA to block keyboard while my program install other components. I would like to create an escape keys combination, like CTRL + SHIFT + KEY.

How can I check if those three keys are pressed? When I check info.vkCode for one single key, it works fine...

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

1 Answers

0
votes
lib.GetAsyncKeyState(VK_LCONTROL)