Open jopemachine opened 3 years ago
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.
@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.
if this behavior is the same on other OSes
Yes, this behavior is same on other OSes.
@jopemachine thank you. It seems that for this particular use you need keydown
event. If I'm mistaken about that then you might want to try keypress
event instead.
It will probably be around a week at least before I can fix this because there are other issues affecting this that need to be fixed first.
@jopemachine thank you. It seems that for this particular use you need
keydown
event. If I'm mistaken about that then you might want to trykeypress
event instead. It will probably be around a week at least before I can fix this because there are other issues affecting this that need to be fixed first.
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 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 vscode
's Input Monitoring
permission on mac.
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