Autohotkey 将脚本转换为在后台运行
当我在前台使用Send和MouseClick而不是ControlSend和ControlClick(wb.Visible=true)运行该脚本时,它工作正常。在后台运行它有什么问题Autohotkey 将脚本转换为在后台运行,autohotkey,Autohotkey,当我在前台使用Send和MouseClick而不是ControlSend和ControlClick(wb.Visible=true)运行该脚本时,它工作正常。在后台运行它有什么问题 code1 := "foobar" url := "https://app.powerbi.com/groups/me/reports/xxx" wb := ComObjCreate("Intern
code1 := "foobar"
url := "https://app.powerbi.com/groups/me/reports/xxx"
wb := ComObjCreate("InternetExplorer.Application") ;create com object
wb.Visible := false ;true to show IE
wb.Navigate(url)
while (wb.busy) ;wait while page loads
sleep 10
ControlSend,, {LWin down}{Up down}
ControlSend,, {LWin up}{Up up}
sleep 20000
ControlClick, left, 1275, 320
sleep 3000
ControlClick, left, 1275, 510
sleep 500
ControlClick, left, 2200, 1380
sleep 3000
ControlClick, left, 2200, 1380
sleep 3000
ControlClick, left, 2200, 1380
sleep 120000
ControlClick, left, 2760, 2000
sleep 500
ControlClick, left, 2760, 2000
sleep 5000
ControlClick, left, 2760, 2000
sleep 3000
ControlClick, left, 2760, 2000
DetectHiddenWindows,On
指令可以检测运行在
背景
#SingleInstance, Force
DetectHiddenWindows, On
Run, Notepad, , Hide ; run notepad in the background
if WinExist("ahk_class Notepad")
ControlSend, Edit1, sending a string to the notepad.exe, Untitled
; verify: wait for 2s to see the effect
sleep 2000
WinShow
击键和字符串可以传递到隐藏窗口或非活动窗口。
例如,下面的代码段启动notepad.exe,发送消息“向notepad.exe发送字符串”,即使notepad正在后台运行
#SingleInstance, Force
DetectHiddenWindows, On
Run, Notepad, , Hide ; run notepad in the background
if WinExist("ahk_class Notepad")
ControlSend, Edit1, sending a string to the notepad.exe, Untitled
; verify: wait for 2s to see the effect
sleep 2000
WinShow
同样地,对于您的问题,它也很有希望工作(无法测试,没有powerbi帐户)
由于AHK仅通过Windows的鼠标和键盘输入方法工作,并且所有这些方法都仅适用于活动窗口(或桌面),因此您无法使用AHK将任何键盘或鼠标操作发送到后台窗口。即使使用IE COM对象访问字段,也意味着页面可见(但不必处于活动状态)。我的意思是,您的页面已经在对象中,只需使用
getElementById()
,getElementsByName()
,getElementsByTagName()
,然后使用.focus()
,。单击()
或.value=
,即可完成所需操作。