Electron - 在 OS 上获取活动文本字段

Electron - Getting active text field on OS

我的意思就像 Windows 10's speech dictation - 你只需在 OS 中有一个活动输入字段时启动它,这样你就可以说话,这个软件将插入到活动输入随便你说什么。
我试过谷歌搜索但没有找到答案。

是否可以通过 Electron 获取活动输入字段?
如果可以,怎么做?

你可以使用 Robotsjs https://github.com/octalmage/robotjs

var robot = require("robotjs");

// Type "Hello World".
robot.typeString("Hello World");

我按照building section and then executing the code in the reply to the issue先安装windows-build-tools的顺序成功安装了robotjs
然后,我在 this answer 的第 3 步执行代码(除了调整 Electron 版本使其适合 gRPC,即 --target=4.0.3 并调整 --abi 值以适应我的节点版本 - 10.15.2,所以它是 --abi=64).

编辑

在某些时候,RobotJS 导致我的应用程序由于某种原因突然退出。
我寻找另一个库并找到 node-key-sender,它不仅解决了这个问题,而且安装起来也简单得多。