wilix-team / iohook

Node.js global keyboard and mouse listener.
https://wilix-team.github.io/iohook
MIT License
1.2k stars 291 forks source link

Hook Sometimes Thinks Keys Are Down When Not #203

Closed metal450 closed 3 years ago

metal450 commented 5 years ago

I'm using an iohook to do something on Windows whenever a hotkey combination (control+space) is pressed. Here's the code:

const ioHook = require("iohook");
ioHook.on("keypress", (event) => {
    if (event.ctrlKey && event.keychar == 32) {
        doIt();
    }
});
ioHook.start();

The problem is, sometimes - randomly - it starts firing when I only type the spacebar (control is not held down). I can keep pressing just spacebar, and it keeps firing. If I then press control once, it "un-sticks," and I can again use the spacebar normally.

pgupt commented 4 years ago

I have similar issue. I opened another ticket. I think this is because iohook remembers previous events even when iohook.stop is called. It should actually reset the events.

metal450 commented 4 years ago

Link to the other ticket?

pgupt commented 4 years ago

https://github.com/wilix-team/iohook/issues/220 I have closed this ticket. It was issue with my knowledge of Vuejs.

metal450 commented 4 years ago

Ah, gotcha, thanks.

borsTiHD commented 4 years ago

I also have some similiar behaviour with my registered hotkey (Ctrl+<). My hotkey is sometimes triggered by just pressing Ctrl.

// STRG+<
this.globalHotkeys.clipboardCheck = ioHook.registerShortcut([29, 0], (keys) => { }, (keys) => { // STRG+<
    this.hotkeyFunction('hotkeyEvent')
})

I'm trying ioHook.stop() and ioHook.start() with setTimeout functions as a workaround, but it didn't work so well. :(

// Edit: Oh sorry for digging up the thread. :'D

ash0x0 commented 3 years ago

This seems to not be a current issue. Please reopen if it is and I will investigate.