yasd/apps/server/plugins/keyboard.js

36 lines
1.0 KiB
JavaScript
Raw Normal View History

2022-04-29 11:21:51 -04:00
const {keyboard, Key } = require('@nut-tree/nut-js');
/**
* A few predefined shortcuts for common actions like copy, paste, etc...
*/
const SHORTCUTS = {
copy: [Key.LeftControl, Key.C],
paste: [Key.LeftControl, Key.V],
cut: [Key.LeftControl, Key.X],
altf4: [Key.LeftAlt, Key.F4]
}
/**
* Will type a string with a provided delay.
* @param {A string or sequence of keys to type. Wrapper for @nut-tree/nut-js keyboard class} string
* @param {Delay between keypresses in milliseconds.} delay
*/
function typeString(string, delay = 0){
keyboard.config.autoDelayMs = delay
keyboard.type(string);
}
/**
* Will type a sequence of keys.
* You can also call on some predefined shortcuts.
* @param {An array of keys using the nutjs key import or key codes} keys
* @example
* typeCommnad(Key.LeftControl, Key.C)
* typeCommand(SHORTCUTS.copy)
*/
function typeCommand(keys){
keyboard.pressKey(...keys);
keyboard.releaseKey(...keys)
}
module.exports = {SHORTCUTS, typeCommand, typeString}