我想打开一个Excel工作表,然后按Ctrl + Q调用宏。但是,ctrl + q部分不起作用。到目前为止,我已经尝试过:
run, %A_Desktop%\test.xlsm, %A_Desktop%\
Send {Ctrl Down}{Q}{Ctrl Up}
这也不起作用:
run, %A_Desktop%\test.xlsm, %A_Desktop%\
Send ^{Q}
答案 0 :(得分:0)
也许“发送”工作太快,而文件没有完全打开。在“发送”之前尝试“ sleep”。
答案 1 :(得分:0)
在向其发送任何命令之前,先使用WinWait
和WinActivate
和WinWaitActive
等待窗口出现:
; https://autohotkey.com/docs/commands/Run.htm#RunAs
; If the script is not elevated, relaunch as administrator and kill current instance
full_command_line := DllCall("GetCommandLine", "str")
if not (A_IsAdmin or RegExMatch(full_command_line, " /restart(?!\S)"))
{
try ; leads to having the script re-launching itself as administrator
{
if A_IsCompiled
Run *RunAs "%A_ScriptFullPath%" /restart
else
Run *RunAs "%A_AhkPath%" /restart "%A_ScriptFullPath%"
}
ExitApp
}
Run, %A_Desktop%\test.xlsm
WinWait, test.xlsm
WinActivate, test.xlsm
WinWaitActive, test.xlsm
Sleep, 300 ; if the program doesn't react immediately after activating
Send {Ctrl Down}q{Ctrl Up}
将test.xlsm
替换为窗口的确切标题,如Window Spy中所示。