Hi all.
I need to create a script that will automatically type/press a key for me at a specific interval regardless of whether or not it's focused. I tried to take a stab at it but I got hopelessly lost because I haven't fiddled with AHK in months and have no prior coding knowledge.
All I need it to do is target a specific window and periodically (every minute or so) just input a key, like E, so that I am consistently typing something in chat overnight. It does not need to press enter otherwise I will just be posting lots of Es.
Can anyone help me out with this, if it's not too difficult a script? Thank you.
AHK script to repeatedly type in a certain window?
Re: AHK script to repeatedly type in a certain window?
Hello,
Ideas are below. This forum also has hundreds or thousands of other scripts that use ControlSend, in case you need more examples.
Ideas are below. This forum also has hundreds or thousands of other scripts that use ControlSend, in case you need more examples.
Code: Select all
#Requires AutoHotkey v2.0
winTitle := 'ahk_exe Notepad.exe'
ctl := 'RichEditD2DPT1' ; Win 11
#HotIf WinExist(wintitle)
F3:: {
ToolTip
SetTimer(go, 60000), go()
SoundBeep 1500
}
#HotIf
go() {
Try ControlSend 'a', ctl, winTitle
Catch as e {
SetTimer , 0
ToolTip e.Message
SoundBeep 1000
}
}
Re: AHK script to repeatedly type in a certain window?
Thank you for your quick reply and sorry for my unsuitably late one. The script you wrote worked excellently for Notepad but unfortunately threw an error when I tried to use it for another application.mikeyww wrote: ↑14 Apr 2024, 18:36Hello,
Ideas are below. This forum also has hundreds or thousands of other scripts that use ControlSend, in case you need more examples.
Code: Select all
#Requires AutoHotkey v2.0 winTitle := 'ahk_exe Notepad.exe' ctl := 'RichEditD2DPT1' ; Win 11 #HotIf WinExist(wintitle) F3:: { ToolTip SetTimer(go, 60000), go() SoundBeep 1500 } #HotIf go() { Try ControlSend 'a', ctl, winTitle Catch as e { SetTimer , 0 ToolTip e.Message SoundBeep 1000 } }
For reference, the error it gave me was:
Error: Parameter #1 of SetTimer must not be omitted in this case.
015: Catch as e
015: {
▶ 016: SetTimer(, 0)
017: ToolTip(e.Message)
018: SoundBeep(1000)
It would also pop up with a box stating "Target control not found." I tried to google this error and other people were saying WindowSpy was useful for helping to fix it but I couldn't figure out the problem.
I'm going to read over the page for SetTimer to see if I can figure it out and fix it for myself but I'm not too hopeful. I received some inspiring words from a programming friend recently that I'm going to try and take with me moving forward, I'm hoping it will help me learn a bit easier.
Re: AHK script to repeatedly type in a certain window?
Although the issues stem from your changes to the script, you have not posted your revised script, so I cannot comment about your revisions.
Who is online
Users browsing this forum: No registered users and 68 guests