【发布时间】:2017-05-07 14:56:49
【问题描述】:
我通过 Ruby WIN32OLE 调用 AutoItX 以在 Windows 中进行一些自动化操作,遇到了一个场景,我必须从屏幕上获取像素颜色并在消息框中显示颜色。 Autoit 没有内置 msgbox 方法,因此必须通过包含外部文件来完成。
这在 Autoit 中可以正常工作,如下所示:
#include <MsgBoxConstants.au3>
Local $iColor = PixelGetColor(10, 100)
MsgBox($MB_SYSTEMMODAL, "", "The decimal color is: " & $iColor)
MsgBox($MB_SYSTEMMODAL, "", "The hex color is: " & Hex($iColor, 6))
由于我从 Ruby 中调用 AutoItX 方法,因此不能以与上述相同的方式包含它。
这是我用于打开安卓模拟器的 ruby 脚本。我正计划使用像素搜索/图像搜索来识别应用并发送鼠标点击与它们进行交互。
require 'win32ole'
# create autoit object from win32ole
puts 'Creating oAutoIt Object...'
oAutoIt = WIN32OLE.new("AutoItX3.Control")
# open MEmu
puts 'Opening MEmu'
MEmu_pid = oAutoIt.Run "C:/Program Files/Microvirt/MEmu/MEmu.exe", "", oAutoIt.SW_SHOWNORMAL
#MEmu_pid = oAutoIt.RunWait "C:/Program Files/Microvirt/MEmu/MEmu.exe", "", oAutoIt.SW_SHOWNORMAL # => pauses the script waits for MEmu to finish.
puts "MEmu is running | PID #{MEmu_pid}"
我需要做的是在当前脚本中包含外部 AutoIt 函数。 我想以标准方式进行(计划稍后扩展)。那么如何将 au3 文件包含到我的 ruby 脚本中呢?
【问题讨论】:
-
PixelGetColor 是标准的 AutoIT 函数。 oAutoIt.PixelGetColor(10,100) 应该可以工作
-
是的,感谢您指出这一点。从那以后我已经编辑了这个问题,现在它清楚地表明我需要一个外部文件来作为一个 msg 框。
标签: ruby include pixel autoit win32ole