- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试将 Typescript 与 Electron 和 RobotJS 一起使用。我是所有这些技术的初学者,因此我对幕后发生的事情缺乏深入的了解,因此我无法真正将这个问题的各个点联系起来。Electron 和我的应用程序工作正常,一切都可以编译,但 RobotJS 无法工作。我得到的错误如下:
ERROR in ./node_modules/robotjs/build/Release/robotjs.node 1:0
Module parse failed: Unexpected character '�' (1:0)
You may need an appropriate loader to handle this file type.
(Source code omitted for this binary file)
我尝试为 Electron 重建 RobotJS,但它仍然不起作用。这是 native Node 模块吗?我不确定,我得先读一下它,弄清楚如果确实如此,我必须用它做什么。
这可以实现吗?谢谢,祝你有美好的一天!
LE:看来我正在尝试使用依赖于 Angular (渲染进程)的 Node (主进程)的robotjs。当我将尝试使用 robotsjs 进行的操作从 Angular 组件移至由 Electron 运行的 main.ts 时,它起作用了。我会尝试找到一种从 Angular 使用它的方法,我猜是进程间通信之类的,因为我现在找不到任何其他方法。仍在等待想法,因为我现在有点一无所知。谢谢!
最佳答案
好的,明白了。基本上你不能直接从 Angular 访问 Electron 的 Node.js API。为此,您需要一个名为 ngx-electron 的出色工具。了解它 here或者只是谷歌一下。安装此工具后,您可以按照大多数指南的指示直接使用其服务,然后使用 Electron remote
来访问 robotjs
。基本上是这样的:
const robot = this._electronService.remote.require('robotjs');
// The example supplied by robotjs
robot.setMouseDelay(2);
const twoPI = Math.PI * 2.0;
const screenSize = robot.getScreenSize();
const height = (screenSize.height / 2) - 10;
const width = screenSize.width;
for (let x = 0; x < width; x++) {
const y = height * Math.sin((twoPI * x) / width) + height;
robot.moveMouse(x, y);
}
可能不是最好的解决方案,但以我目前对这些技术的有限了解,这将是必须的。我对意见持开放态度。
感谢您的宝贵时间,祝您玩得愉快!
关于node.js - Angular、Electron、TypeScript 和 RobotJS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54388226/
当我运行命令“npm install robotjs -g”时,它给了我这个错误。 robotjs@0.5.1 install C:\Users\Ehsan\AppData\Roaming\npm\n
我正在尝试将 Typescript 与 Electron 和 RobotJS 一起使用。我是所有这些技术的初学者,因此我对幕后发生的事情缺乏深入的了解,因此我无法真正将这个问题的各个点联系起来。Ele
我是一名优秀的程序员,十分优秀!