問題描述
想象一下,當(dāng)從控制臺(tái)調(diào)用 NodeJS 模塊時(shí),會(huì)輸出一些介紹性消息,然后等待用戶輸入(單擊 enter 或 esc).這個(gè)模塊已經(jīng)擁有并完成了我們需要的一切,除了 - 等待用戶輸入提示.所以我們想知道(我個(gè)人對(duì) NodeJS 很陌生)是否可以以編程方式執(zhí)行控制臺(tái)模塊并在其上觸發(fā)輸入事件,這樣它就不會(huì)等待并立即繼續(xù)工作?
Imagine that a NodeJS module, when invoked from console, outputs some introductory messages and then waits for user input (click enter or esc). This module already has and does everything we require, except that - wait-for-user-input prompt. So we wonder (I'm personally very new to NodeJS) if it is possible to execute console module programmatically and trigger an input event on it, so that it doesn't wait and proceed with the job right away?
推薦答案
你可以使用 RobotJS 來解決這個(gè)問題.
You could use possibly use RobotJS for this.
示例代碼:
var robot = require("robotjs");
// Type user's password or something.
robot.typeString("abc123");
這篇關(guān)于是否可以在 NodeJS 中模擬鍵盤/鼠標(biāo)事件?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!