iohook icon indicating copy to clipboard operation
iohook copied to clipboard

High Cpu usage of iohook in the electron . Currently it is going upto 50-80%

Open deepanshushukla opened this issue 4 years ago • 3 comments
trafficstars

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

deepanshushukla avatar Oct 08 '21 04:10 deepanshushukla

any update on the behaviour? deciding whether to use it or not for a new project.

shoaib30 avatar Jan 13 '22 06:01 shoaib30

The issue was multiple event listeners were created every time I reload the app. So make sure you clear event listeners before registering again.

deepanshushukla avatar Jan 13 '22 06:01 deepanshushukla

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

shoaib30 avatar Jan 13 '22 09:01 shoaib30