問題描述
想象一下,當從控制臺調用 NodeJS 模塊時,會輸出一些介紹性消息,然后等待用戶輸入(單擊 enter 或 esc).這個模塊已經擁有并完成了我們需要的一切,除了 - 等待用戶輸入提示.所以我們想知道(我個人對 NodeJS 很陌生)是否可以以編程方式執行控制臺模塊并在其上觸發輸入事件,這樣它就不會等待并立即繼續工作?
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 來解決這個問題.
You could use possibly use RobotJS for this.
示例代碼:
var robot = require("robotjs");
// Type user's password or something.
robot.typeString("abc123");
這篇關于是否可以在 NodeJS 中模擬鍵盤/鼠標事件?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!