Detect and control the mouse, keyboard and screen.
npm install xoi
const { mouse, keyboard, screen } = require("xoi");
// Realistically move the mouse to x=100 y=100
mouse.move(100, 100, { smooth: true });
// Right-click
mouse.click("right");
// When mouse clicked
mouse.on("click", ({ button }) => {
console.log(`The ${button} mouse button was clicked.`);
});
// Type text
keyboard.type("Hello World!");
// When key pressed
keyboard.on("press", ({ key }) => {
console.log(`${key} was pressed.`);
});
// Get hex code of pixel at x=100 y=100
const hex = screen.pixelAt(100, 100);
console.log(`The colour #${hex} is at x=100, y=100`);
Type: number
The x coordinate of the mouse.
Type: number
The y coordinate of the mouse.
Type: number
Default: 10
The amount of time to wait in milliseconds after a mouse press before executing another.
Move the mouse to a specific location.
Drag the mouse from it's current location to the specified location.
Scroll the mouse to the specified location.
Type: number
The x coordinate of the target location.
Type: number
The y coordinate of the target location.
Type: object
Type: boolean
Default: true
Treat x
and y
as relative values from the current location.
Only available for mouse.move
Type: boolean
Default: false
Smoothly move the mouse.
Press and release a mouse button.
Click at a specific location.
Press down a mouse button.
Release a mouse button that is pressed down.
Default: left
The mouse button to press. Can be left
, right
or middle
The x coordinate of the target location.
The y coordinate of the target location.
You can listen for mouse events with mouse.on
.
const { mouse } = require("xoi");
mouse.on("click", ({ button }) => {
console.log(`You clicked with the ${button} mouse button!`);
});
Type: number
The number associated with the mouse button that was clicked.
Type: number
The amount of times in a row this mouse action has been performed. The counter resets when another action is done.
Type: number
The x coordinate of the mouse location.
Type: number
The y coordinate of the mouse location.
Type: number
The distance scrolled.
Type: number
The scrolling direction. Can be 1
or -1
.
Type: number
The x coordinate of the mouse location.
Type: number
The y coordinate of the mouse location.
Type: number
Default: 10
The amount of time in milliseconds to wait after pressing a key before pressing another.
Type some text.
Type: string
The text to type.
Type: object
The interval in milliseconds to wait between presses.
Press a key.
Hold down a key.
Release a key that is held down.
Type: string
The key to press.
Type: string or array
The key modifiers to use. Can be alt
, command
, control
or shift
either as a string or in an array.
You can listen for keyboard events with keyboard.on
.
const { keyboard } = require("xoi");
keyboard.on("press", ({ key }) => {
console.log(`You pressed the ${key} key!`);
});
Type: string
The key that was pressed.
Type: number
The ID of the key that was pressed.
Type: boolean
Whether the shift button was held down.
Type: boolean
Whether the alt button was held down.
Type: boolean
Whether the ctrl button was held down.
Type: boolean
Whether the meta button was held down.
keyboard.shortcut
exposes an event listener that emits when keyboard shortcuts are executed.
const { keyboard } = require("xoi");
keyboard.shortcut.on("ctrl+a", () => {
console.log("ctrl+a pressed!")
})
Type: number
The screen width.
Type: number
The screen height.
Get the hex code for the pixel colour at a specific coordinate.
Type: number
The x coordinate of the pixel location.
Type: number
The y coordinate of the pixel location.
Type: number
Default: 0
The coordinates on the screen for the top-left corner of the screenshot.
Type: number
Default: 0
The height of the screenshot.
Type: number
Default: screen width
The width of the screenshot.
Type: number
Default: screen height
The height of the screenshot.
See https://github.com/octalmage/robotjs#building and https://github.com/wilix-team/iohook/blob/master/docs/os-support.md.