mirror of
https://github.com/Mintplex-Labs/nut.js.git
synced 2026-07-25 20:45:27 -04:00
1.8 KiB
1.8 KiB
nut.js Keyboard Control
nut.js allows to simulate keyboard input by typing text or pressing / releasing single keys or key combinations.
Configuration
The nut.js keyboard comes with a config object which allows to configure it's behaviour.
autoDelayMs
keyboard.config.autoDelayMs configures the delay between keypresses.
type
type allows one to type either strings or Keys
const {keyboard, Key} = require("@mintplex-labs/nut-js");
describe("Keyboard test", () => {
it("should open Spotlight on macOS", async () => {
await keyboard.type(Key.LeftSuper, Key.Space);
await keyboard.type("calculator");
});
});
pressKey
pressKey will press and hold multiple keys.
const {keyboard, Key} = require("@mintplex-labs/nut-js");
describe("Keyboard test", () => {
it("should press and release Alt+F4", async () => {
await keyboard.pressKey(Key.LeftAlt, Key.F4);
await keyboard.releaseKey(Key.LeftAlt, Key.F4);
});
});
releaseKey
releaseKey will release multiple keys again.
const {keyboard, Key} = require("@mintplex-labs/nut-js");
describe("Keyboard test", () => {
it("should press and release Alt+F4", async () => {
await keyboard.pressKey(Key.LeftAlt, Key.F4);
await keyboard.releaseKey(Key.LeftAlt, Key.F4);
});
});