Morning everyone,
I have just found about AHK and it seems amazing.
However, i have some issues in running the script. I would like to make a script where my gaming character keeps hitting SPACEBAR and the key button 1 continuously, but only on the game window. So, then i can minimise that window and do something else meanwhile.
I have tried running something but it does not work.
Anyone able to help me please?
Script for hitting spacebar and button 1 for a game
-
- Posts: 3
- Joined: 30 Nov 2022, 04:32
Re: Script for hitting spacebar and button 1 for a game
Welcome to this AutoHotkey forum!
When you have a script that you are developing, posting it is a good idea, so that you can get more specific feedback about what went wrong.
When you have a script that you are developing, posting it is a good idea, so that you can get more specific feedback about what went wrong.
-
- Posts: 3
- Joined: 30 Nov 2022, 04:32
Re: Script for hitting spacebar and button 1 for a game
This is what i wrote using google and by reading some bits of the tutorial guide, but i just started 1 hour ago using AHK.
[Mod edit: [code][/code] tags added.]
Code: Select all
^L::
WinGet, programid,List, "Programm Title"
toggle:=!toggle
While toggle{
send {space},,{Enter}, ahk_id %programid1%
send {1},,{Enter}, ahk_id %programid1%
}
return
Re: Script for hitting spacebar and button 1 for a game
That is very helpful. The AHK documentation is a source of information for the syntax of every command. The commands (e.g., Send vs. ControlSend) are not interchangeable in their syntax, so you have to stick with the program!
I recommend starting with a short test script. This will enable you to determine whether your target window or windows respond to ControlSend. You can test this in Notepad first, and then change the first line. If you verify that the script works in your window, then the script can be expanded.
If you click on the posted commands, you can learn more about them.
Would try this without minimizing any windows.
I recommend starting with a short test script. This will enable you to determine whether your target window or windows respond to ControlSend. You can test this in Notepad first, and then change the first line. If you verify that the script works in your window, then the script can be expanded.
Code: Select all
winTitle = ahk_exe notepad.exe
#If WinExist(winTitle)
^l::
ControlSend,, {Space}1
Return
#If
Would try this without minimizing any windows.
-
- Posts: 3
- Joined: 30 Nov 2022, 04:32
Re: Script for hitting spacebar and button 1 for a game
So if how where it says (WinTitle) i would need to add the title of the window application? and change the path from ahk_exe notepad.exe to the application path?
Re: Script for hitting spacebar and button 1 for a game
Yes. See WinTitle.
In most cases, the format or syntax used for a process in a WinTitle would be ahk_exe process.exe, but AHK will accept a full path instead of a process name alone. If you do not have a reason to specify the path, I would specify the process instead (as shown).
https://www.autohotkey.com/docs/misc/WinTitle.htm#ahk_exe
Alternative:
In most cases, the format or syntax used for a process in a WinTitle would be ahk_exe process.exe, but AHK will accept a full path instead of a process name alone. If you do not have a reason to specify the path, I would specify the process instead (as shown).
https://www.autohotkey.com/docs/misc/WinTitle.htm#ahk_exe
Alternative:
Code: Select all
#If WinExist("ahk_exe notepad.exe")
^l::
ControlSend,, {Space}1
Return
#If