Node.js JavaScript: Simulate Keypress on Server (Like a Macro)

北城余情 提交于 2019-12-03 16:38:34

I made a node module to do this too: https://github.com/kylepaulsen/kbm-robot

var robot = require("kbm-robot");

robot.startJar();

robot.press("alt")
    .press("tab")
    .sleep(100)
    .release("tab")
    .release("alt")
    .sleep(100)
    .typeString("Hello World!")
    .go()
    .then(robot.stopJar);

Apparently, there's a win_keyboard module in the npm registry that somebody wrote to control the keyboard in Windows. You can run npm install win_keyboard and use that; it appears to do exactly what you want.

You may try an alternative to RobotJS. It is a very small and still cross platform library to send keys to your operational system called node-key-sender. I developed after getting frustrated with RobotJS and kbm-robot.

Install it with npm install --save-dev node-key-sender.

And send a text to the keyboard using:

var ks = require('node-key-sender');
ks.sendText('This is my text');

Check out the documentation page: https://www.npmjs.com/package/node-key-sender.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!