iohook
iohook copied to clipboard
High Cpu usage of iohook in the electron . Currently it is going upto 50-80%
Expected Behaviour: iohook should not increase CPU usage that much Currently it goes up to 80%. It should not downgrade the performance
Current Behavior
After some time of usage(like mouse move and mouseclick) sometimes it goes till 70-80%
The code i am using
export const initActiveScreenListener = (mainWindow) => {
let activeDisplay = screen.getPrimaryDisplay();
const onMouseClick = () => {
const currentDisplay = screen.getDisplayNearestPoint(
screen.getCursorScreenPoint()
);
if (activeDisplay.id !== currentDisplay.id) {
activeDisplay = currentDisplay;
mainWindow.webContents.send(ACTIVE_SCREEN_CHANGED, { ...activeDisplay });
}
};
const displayRemoved = (_, removedDisplay) => {
if (removedDisplay.id === activeDisplay.id) {
activeDisplay = screen.getPrimaryDisplay();
mainWindow.webContents.send(ACTIVE_SCREEN_CHANGED, { ...activeDisplay });
}
};
const debouncedClick = debounce(onMouseClick, 0);
ioHook.on('mouseclick', debouncedClick);
ioHook.on('mouseup', debouncedClick);
screen.on(DISPLAY_REMOVED, displayRemoved);
ioHook.start();
};
IOHook Version:0.9.3 electron : 12.0.4 node: 14.0 Operating System and version (desktop or mobile): Windows 10
any update on the behaviour? deciding whether to use it or not for a new project.
The issue was multiple event listeners were created every time I reload the app. So make sure you clear event listeners before registering again.
The issue was multiple event listeners were created every time I reload the app. So make sure you clear event listeners before registering again.
Got it! thank you for the input :)
This issue can be marked as resolved