New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Keydown event only triggered by modifier key with Electron 12 #332
Comments
I don't know why this happens, the bug doesn't happen on production mode. |
@jopemachine it'll be some time before I get around to electron 12 and 13 but do provide more information if you can, such as if this behavior is the same on other OSes and what you're using to build your code for production. |
Now I've made the project public. here is my code using iohook.
Yes, this behavior is same on other OSes. |
@jopemachine thank you. It seems that for this particular use you need |
I appreciate your hard work. I tried to replaceing the event with the keypress event, but unfortunately keypress event was not triggered. Here is my test code. useEffect(() => {
ioHook.on('keypress', (e: IOHookKeyEvent) => {
// not works on development mode, production mode both.
console.log('triggered!');
if (cpyKeyPressed(e)) {
setTimeout(() => {
const copiedText = clipboard.readText();
if (copiedText !== '') {
ipcRenderer.send(IPCRendererEnum.dispatchAction, {
destWindow: 'clipboardHistoryWindow',
actionType: actionTypes.PUSH_CLIPBOARD_STORE,
args: JSON.stringify({
text: clipboard.readText(),
date: new Date().getTime(),
}),
});
}
}, 25);
}
if (isShiftKey(e)) {
handleDoubleKeyModifier('shift');
} else if (isAltKey(e)) {
handleDoubleKeyModifier('alt');
} else if (isCtrlKey(e)) {
handleDoubleKeyModifier('ctrl');
} else if (isMetaKey(e)) {
handleDoubleKeyModifier('cmd');
}
});
ioHook.start();
return () => {
ioHook.removeAllListeners();
ioHook.unload();
};
}, []); |
I think I also once encountered that issue on macOS. For me, it was related to the fact that the terminal application used to start my application no longer had the required accessibility privileges (for keyboard input). After enabling them again in the system settings, everything worked again. |
I appreciate for your comment :) It works well on dev mode now after activating I think maybe there is another similar kind of permission setting in other OSs too. |
Expected Behavior
Keydown event is triggered by all type of key down
Current Behavior
Only detect modifier key (cmd, ctrl, alt...).
Alphabet, number keys are not detected.
Possible Solution
I have no idea why this is happening.
Steps to Reproduce (for bugs)
Context
Your Environment
The text was updated successfully, but these errors were encountered: