gpt4 book ai didi

load - 如何在程序启动时发送热键?

转载 作者:行者123 更新时间:2023-12-02 03:41:45 25 4
gpt4 key购买 nike

我在任何地方都找不到如何在程序启动时自动发送热键。这些简单的尝试根本不起作用:

#IfWinActive, ahk_class Notepad
Send abcd
Send !vw
return

ControlSend, Edit1, This is a line of text in the notepad window., Untitled

脚本应该能够:

  • 等待程序加载后再执行
  • 在同一程序的新窗口启动时执行
  • 但不要对已经执行且仍然存在的执行这样做

最佳答案

#Persistent
SetTimer, SendHotkey, 300
return

SendHotkey:
If !WinExist("ahk_class Notepad")
return ; do nothing
; otherwise:
SetTimer, SendHotkey, off
WinActivate, ahk_class Notepad
WinWaitActive, ahk_class Notepad
Send abcd
WinWaitClose, ahk_class Notepad
SetTimer, SendHotkey, on ; repeat the action next time the program starts
return

https://autohotkey.com/docs/commands/SetTimer.htm#Examples

编辑:

使其在每次启动新窗口时都有效,但已打开的窗口不会再次受到影响:

#Persistent
SetTimer, SendHotkey, 300
return


SendHotkey:
If !WinExist("ahk_class Notepad")
return ; do nothing
; otherwise:
WinGet, Notepad_ID, list, ahk_class Notepad ; Get ID list of all opened Notepad windows
Loop, %Notepad_ID% ; retrieves each ID from the list, one at a time
{
this_Notepad_ID := Notepad_ID%A_Index% ; "A_Index" contains the number of the current loop iteration
If !InStr(Notepad_IDs, this_Notepad_ID) ; If the variable "Notepad_IDs" does not contain the current ID
{
WinActivate, ahk_id %this_Notepad_ID% ; "ahk_id" is used to identify a window based on the windows unique ID
WinWaitActive, ahk_id %this_Notepad_ID%
Send abcd
Notepad_IDs .= this_Notepad_ID ? this_Notepad_ID " " : "" ; The dot is used to concatenate (join) the IDs into a single variable. See Operators in expressions
}
}
return

关于load - 如何在程序启动时发送热键?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48404667/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com