How to use the iohook.on function in iohook

To help you get started, we’ve selected a few iohook examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ahkohd / switch / src / switch.ts View on Github external
// if altgr is disabled do not show dock...
        if (disableKeyUpListen && event.rawcode != 164) {
            if (disableKeyUpListenTimeout) clearTimeout(disableKeyUpListenTimeout);
            disableKeyUpListenTimeout = setTimeout(() => {
                clearTimeout(disableKeyUpListenTimeout)
                disableKeyUpListen = false;
            }, 1000);
            return;
        };
        fnMethod(event);
    });

    /**
     * Fires on user's keydown
     */
    ioHook.on('keydown', event => {
        if (event.altKey) {
            // If alt key is pressed, show dock
            // if altgr is disabled do not show...
            if (config.disableAltGr && event.rawcode == 165) {
                disableKeyUpListen = true;
                return;
            }
            interChannel.sendShowClient();
        }
    });
}

if (process.platform == "darwin") {

    // MacOS switching strategy ...
github ahkohd / switch / src / switch.ts View on Github external
* @param  {} event
 */
function fnMethod(event) {
    // if altgr is disabled do not switch...

    if (event.altKey) {
        react(event);
    }
}

if (process.platform == 'win32') {
    /**
    * Fires on user's keyup
    */

    ioHook.on('keyup', event => {
        // if altgr is disabled do not show dock...
        if (disableKeyUpListen && event.rawcode != 164) {
            if (disableKeyUpListenTimeout) clearTimeout(disableKeyUpListenTimeout);
            disableKeyUpListenTimeout = setTimeout(() => {
                clearTimeout(disableKeyUpListenTimeout)
                disableKeyUpListen = false;
            }, 1000);
            return;
        };
        fnMethod(event);
    });

    /**
     * Fires on user's keydown
     */
    ioHook.on('keydown', event => {
github ahkohd / switch / switch.js View on Github external
{
    notifier.notify(
        {
          title: 'Switch - '+title,
          message: message,
        //   icon: path.join(__dirname, 'coulson.jpg'), // Absolute path (doesn't work on balloons)
          sound: true, // Only Notification Center or Windows Toasters
          wait: true // Wait with callback, until user action is taken against notification
        });

        notifier.on('click', function(notifierObject, options, event) {
            // Triggers if `wait: true` and user clicks notification
          });
}

ioHook.on('keyup', event => {
    // 1. When use holds the alt key
    if (event.altKey) {
        // 2. Find the app with the registered keycode that match the keycode the user just press
        let whichHotWindowToOpen = hotSwitches.filter(hot => hot.keycode == event.keycode);
        // 3. If found:
        if (whichHotWindowToOpen.length > 0) {
            // 4. We only use the first match
            whichHotWindowToOpen = whichHotWindowToOpen[0];
            try {
                // 5. Get all windows that matches the app title
                let windows = windowManager.getWindows().filter(window => window.getTitle().includes(whichHotWindowToOpen.name));
                // 6. If none is found exit the function
                if (windows == null  || windows.length == 0) {
                    sendMsg('Yikes 🤔', `Ops! It seems like ${whichHotWindowToOpen.name} is yet opened. Click to launch app! 🚀`);
                    return;
                }
github CopyTranslator / CopyTranslator / src / tools / windowController.ts View on Github external
Date.now() - this.lastDown > 100 &&
        Math.abs(this.newX - this.lastX) + Math.abs(this.newY - this.lastY) > 10
      ) {
        simulate.copy();
        this.copied = true;
      }
    });

    ioHook.on("mousedown", (event: MouseEvent) => {
      this.lastDown = Date.now();
      this.lastX = event.x;
      this.lastY = event.y;
      this.copied = false;
    });

    ioHook.on("mousedrag", (event: MouseEvent) => {
      this.drag = true;
      this.newX = event.x;
      this.newY = event.y;
    });
    //注册的指令。send到主进程main.js中。
    // Register and start hook
    ioHook.start(false);
  }
}
github living-room / turing / src / processes / mouse.js View on Github external
return
  if (!room) {
    const Room = require('@living-room/client-js')
    room = new Room()
  }

  let start = new Date()

  const ioHook = require('iohook')

  // TODO: get window size programattically, and listen to screen size changes
  const windowSize = { width: 1920, height: 1080 }

  const lastMousePositions = []

  ioHook.on('mousemove', event => {
    if (new Date() - start < 16) return
    start = new Date()

    const x = event.x / windowSize.width
    const y = event.y / windowSize.height

    lastMousePositions.unshift({ x, y })

    if (lastMousePositions.length > 9) lastMousePositions.pop()

    const alphabet = 'abcdefghijklmnopqrstuvwxyz'
    for (let [i, pos] of lastMousePositions.entries()) {
      const b = 255 - i * 10
      const r = 30 - i * 2
      const l = alphabet[i]
      const fact = `mouse${l} is a (${b}, ${b}, ${b}) circle at (${pos.x}, ${
github typie / typie / static / packages / Mouse / index.js View on Github external
activate(pkgList, item=null, cb=null) {
        globalShortcut.register(this.pkgConfig.keys.escape, () => this.deactivate());
        globalShortcut.register(this.pkgConfig.keys.up, () => {});
        globalShortcut.register(this.pkgConfig.keys.left, () => {});
        globalShortcut.register(this.pkgConfig.keys.down, () => {});
        globalShortcut.register(this.pkgConfig.keys.right, () => {});
        globalShortcut.register(this.pkgConfig.keys.click, () => {});
        globalShortcut.register(this.pkgConfig.keys.speed, () => {});
        globalShortcut.register(this.pkgConfig.keys.rightClick, () => {});

        ioHook.on("keyup", event => this.getPressesObj(event, false));
        ioHook.on("keydown", event => this.getPressesObj(event, true));

        let keys = this.keys;
        this.intervalLoop = setInterval(() => {
            if (keys.up || keys.left || keys.down || keys.right) {
                let pos = robot.getMousePos();
                let newX = pos.x;
                let newY = pos.y;
                let amount = 7;
                if (keys.speed) {amount = 25}
                if (keys.up) {newY -= amount}
                if (keys.left) {newX -= amount}
                if (keys.down) {newY += amount}
                if (keys.right) {newX += amount}
                robot.moveMouse(newX, newY);
            }
github CopyTranslator / CopyTranslator / src / background.ts View on Github external
const sendMouseEvent = () => {
  ioHook.on("mousedown", (event:MouseEvent) => {
    focusWin.webContents.send("news", event);
  });
  ioHook.on("mouseup", (event:MouseEvent) => {
    isFollow = false;
  });
  ioHook.on("mousedrag",(event:MouseEvent) => {
    if (isFollow && event.button === 0) {
      let x_now = event.x;
      let y_now = event.y;
      let dx = x_now - x;
      let dy = y_now - y;
      x = x_now;
      y = y_now;
      let bounds = focusWin.getBounds();
      bounds.x += dx;
      bounds.y += dy;
github CopyTranslator / CopyTranslator / src / tools / windowController.ts View on Github external
break;
      }
    });
    ioHook.on("keydown", (event: any) => {
      this.ctrlKey = event.ctrlKey;
    });
    ioHook.on("keyup", (event: any) => {
      if (event.keycode == 29) {
        this.ctrlKey = false;
      } else {
        this.ctrlKey = event.ctrlKey;
      }
    });

    //字体缩放
    ioHook.on("mousewheel", (event: any) => {
      if (!this.ctrlKey) return;
      const window = BrowserWindow.getFocusedWindow();
      if (window)
        window.webContents.send(MessageType.WindowOpt.toString(), {
          type: WinOpt.Zoom,
          rotation: event.rotation
        });
    });
    ioHook.on("mouseup", (event: MouseEvent) => {
      //模拟点按复制
      if (
        this.dragCopy &&
        !this.copied &&
        Date.now() - this.lastDown > 100 &&
        Math.abs(this.newX - this.lastX) + Math.abs(this.newY - this.lastY) > 10
      ) {
github ahkohd / switch / build / switch.js View on Github external
else {
        if (event.rawcode >= 48 && event.rawcode <= 58) {
            interChannel.sendShowClient();
            utils_1.switchMessage(enums_1.Switch.ERROR_NOTI, { title: text_1.default.errorTitle, message: text_1.default.noHotApp(event.rawcode - 48), hotApp: hotApp });
        }
    }
}
function fnMethod(event) {
    if (event.altKey) {
        react(event);
    }
}
ioHook.on('keyup', event => {
    fnMethod(event);
});
ioHook.on('keydown', event => {
    if (event.altKey) {
        interChannel.sendShowClient();
    }
});
ioHook.start();
ioHook.start(true);
utils_1.registerNotifierOnClick();
interChannel.emitter.on('update-hot-apps', (happs) => {
    hotapps = happs;
    log(enums_1.Switch.LOG_INFO, 'Hot apps update received', hotapps);
    utils_1.saveHotApps(happs);
});
interChannel.emitter.on('config-update', (settings) => {
    log(enums_1.Switch.LOG_INFO, 'Config update update received', settings);
    config = settings;
    utils_1.saveConfig(settings);
github CopyTranslator / CopyTranslator / src / background.ts View on Github external
const sendMouseEvent = () => {
  ioHook.on("mousedown", (event:MouseEvent) => {
    focusWin.webContents.send("news", event);
  });
  ioHook.on("mouseup", (event:MouseEvent) => {
    isFollow = false;
  });
  ioHook.on("mousedrag",(event:MouseEvent) => {
    if (isFollow && event.button === 0) {
      let x_now = event.x;
      let y_now = event.y;
      let dx = x_now - x;
      let dy = y_now - y;
      x = x_now;
      y = y_now;
      let bounds = focusWin.getBounds();
      bounds.x += dx;
      bounds.y += dy;
      focusWin.setBounds(bounds);
    }
  });

iohook

Node.js global keyboard and mouse hook

MIT
Latest version published 3 years ago

Package Health Score

46 / 100
Full package analysis