如何使 AutoHotkey 中的向下箭头和回车键正常工作?

huangapple go评论50阅读模式
英文:

How to make down arrow and enter key working in AutoHotkey?

问题

  1. 如何让这部分工作或如何进行调试?
  2. 如何切换到“Graph”选项卡?此选项卡的 ClassNN 以及其他信息为 TPageControl1。如何进行选择?
  3. 更一般的情况下,如何让一个 ClassNN 唯一且我知道其名称的按钮工作?
英文:

I have just started with writing scripts in AutoHotkey. I got the following working smoothly: I opened my program, performed Ctrl+I, then bottom option from dropdown menu. Here is my script:

Run, path\name_of_my_program.exe

; Wait for the name_of_my_program app window to become active (optional, but recommended)
WinWaitActive, ahk_exe name_of_my_program.exe, , 10 ; Wait for the app window to become active within 10 seconds (adjust the timeout as needed)

if ErrorLevel
{
    MsgBox, name_of_my_program did not open successfully.


	}
else
{
    ; Simulate the shortcut Ctrl+I
    SendInput, ^i
    ; Wait for the "Choose File" window to appear
    ; WinWaitActive, Open
    ; Simulate pressing the Tab key (choose the Import option)
    SendInput, S ^{Tab}
    ; Simulate clicking on the "I" key
    SendInput, I
	; Send Tab key six times
    SendInput, {Tab 6}
	; Send Arrow Down key twice
	SendInput, {Down}
	; Send Enter key once
	SendInput, {Enter}
	
}

My expectation: After this step

; Send Tab key six times
    SendInput, {Tab 6}

I would like to go down twice with Down keyboard and click on Enter key. Hence, I wrote this

	; Send Arrow Down key twice
	SendInput, {Down}
	; Send Enter key once
	SendInput, {Enter}

However, this part does not work. My questions are

  1. How can I get this part working or how to debug it?
  2. How can I change to Graph tab? ClassNN for thistab and other are TPageControl1. How can I make this choice?
  3. More general version of 2. How to get a button working whose ClassNN is unique and I know the name of it?

答案1

得分: 0

我刚刚弄清楚了!原来我应该在else后面添加KeyWait LWin。然后,我添加了暂停时间,以便程序花时间打开屏幕来执行命令。

这是更新后的解决方案:

Run, path\name_of_my_program.exe

; 等待name_of_my_program应用程序窗口变为活动状态(可选,但建议)
WinWaitActive, ahk_exe name_of_my_program.exe, , 10 ; 在10秒内等待应用程序窗口变为活动状态(根据需要调整超时时间)

if ErrorLevel
{
    MsgBox, name_of_my_program未成功打开。
}
else
{
    KeyWait LWin
    ; 模拟快捷键Ctrl+I
    SendInput, ^i
    ; 等待“选择文件”窗口出现
    ; WinWaitActive, 打开
    ; 模拟按Tab键(选择导入选项)
    SendInput, S ^{Tab}
    ; 模拟点击“I”键
    Sleep 100
    SendInput, I
    ; 发送Tab键六次
    Sleep 100
    SendInput, {Tab 6}
    ; ClipWait, 2
    ; 发送向下箭头键两次
    Sleep 100
    SendInput, {Down}
    ; 发送向下箭头键两次
    Sleep 100
    SendInput, {Down}
    ; 发送Enter键一次
    Sleep 100
    SendInput, {Enter}
    ; 发送Right键一次
    Sleep 100
    SendInput, {Right 4}
    ; 发送Enter键一次
    Sleep 100
    SendInput, {Tab 3}
    ; 发送Enter键两次
    Sleep 100
    SendInput, {Enter 2}
    ; 发送Left键一次
    Sleep 100
    SendInput, {Home}
    ; 模拟点击“G”键
    Sleep 100
    SendInput, G_
    ; 发送Enter键两次
    Sleep 100
    SendInput, {Enter}
}
英文:

I just figured it out! It turns out that I should add KeyWait LWin after else. Then, I added pause time so that the program takes its time to open screen to execute the command.

Here is the updated solution:

Run, path\name_of_my_program.exe

; Wait for the name_of_my_program app window to become active (optional, but recommended)
WinWaitActive, ahk_exe name_of_my_program.exe, , 10 ; Wait for the app window to become active within 10 seconds (adjust the timeout as needed)


if ErrorLevel
{
    MsgBox, name_of_my_program did not open successfully.
}
else
{
	KeyWait LWin
    ; Simulate the shortcut Ctrl+I
    SendInput, ^i
    ; Wait for the "Choose File" window to appear
    ; WinWaitActive, Open
    ; Simulate pressing the Tab key (choose the Import option)
    SendInput, S ^{Tab}
    ; Simulate clicking on the "I" key
	Sleep 100
    SendInput, I
    ; Send Tab key six times
	Sleep 100
    SendInput, {Tab 6}
	; ClipWait, 2
    ; Send Arrow Down key twice
    Sleep 100
	SendInput, {Down}
	    ; Send Arrow Down key twice
    Sleep 100
	SendInput, {Down}
    ; Send Enter key once 
    Sleep 100
    SendInput, {Enter}
	; Send Right key once 
    Sleep 100
    SendInput, {Right 4}
	; Send Enter key once 
    Sleep 100
    SendInput, {Tab 3}
	; Send Enter key twice 
    Sleep 100
    SendInput, {Enter 2}
	; Send Left key once 
    Sleep 100
    SendInput, {Home}
	; Simulate clicking on the "G" key
	Sleep 100
    SendInput, G_
	; Send Enter key twice 
    Sleep 100
    SendInput, {Enter}
}

huangapple
  • 本文由 发表于 2023年7月4日 22:50:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/76613816.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定