简体   繁体   English

Python 中 pywinauto 的 Node.js 等效项是什么?

[英]What is the Node.js equivalent of pywinauto in Python?

I have many scripts written in python which use the pywinauto library.我有许多使用 pywinauto 库的 python 编写的脚本。 These scripts are opening programs on Windows, doing things within them, etc. Now that I've begun to learn Node.js, I have only found so far Robot.js, which is certainly promising but lacks the ability I think to get into the nitty-gritty details like pywinauto does.这些脚本是在Windows上打开程序,在里面做事等等。现在我已经开始学习Node.js了,到现在才发现Robot.js,肯定很有前途,但缺乏我认为深入的能力- 像 pywinauto 一样的细节。

For example, suppose I wanted to locate a program called "Wordperfect" if it was open or not and if open, kill the program and reopen it.例如,假设我想定位一个名为“Wordperfect”的程序是否打开,如果打开,则终止该程序并重新打开它。 Here's how I am doing that in python using pywinauto:这是我在 python 中使用 pywinauto 的方法:

from pywinauto import Desktop, Application

# Starts Wordperfect
wp_open = "wpwin14.exe" in (p.name() for p in psutil.process_iter())

if wp_open == False: # detects Wordperfect is closed
    app = Application().start(cmd_line=u'"C:\\Program Files (x86)\\Corel\\WordPerfect Office X4\\Programs\\wpwin14.exe" ')

if wp_open == True: # detects Wordperfect is open
    app = Application().connect(class_name='WordPerfect.14.00') # title=u'WordPerfect X4 - Document1 (unmodified)', 
    wordperfect = app[u'WordPerfect.14.00']
    # Kills Wordperfect
    app.Kill_() 
    # Reopens Wordperfect
    app = Application().start(cmd_line=u'"C:\\Program Files (x86)\\Corel\\WordPerfect Office X4\\Programs\\wpwin14.exe" ')

This is just the beginning of my script.这只是我剧本的开始。 It becomes much more complex from here.从这里开始变得更加复杂。 Unfortunately, so far I have not found a specific way to do this within Node.js.不幸的是,到目前为止,我还没有找到在 Node.js 中执行此操作的特定方法。 Can anyone let me know if there is and how to do it?谁能告诉我是否有以及如何做? I've been checking out child-process in the Node.js documentation but from what I saw in the examples, it's not clear how to recreate what I have in python above.我一直在 Node.js 文档中检查child-process ,但从我在示例中看到的内容来看,尚不清楚如何重新创建我在上面的 python 中拥有的内容。

Ultimately I found Robot.js which does the same thing on windows except create a bundle of EXE.最终我发现 Robot.js 在 windows 上做同样的事情,除了创建一个 EXE 包。

https://www.npmjs.com/package/robotjs https://www.npmjs.com/package/robotjs

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM