Script for hitting spacebar and button 1 for a game

Ask gaming related questions (AHK v1.1 and older)
BlackVortex
Posts: 3
Joined: 30 Nov 2022, 04:32

Script for hitting spacebar and button 1 for a game

Post by BlackVortex » 30 Nov 2022, 04:37

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?

User avatar
mikeyww
Posts: 26437
Joined: 09 Sep 2014, 18:38

Re: Script for hitting spacebar and button 1 for a game

Post by mikeyww » 30 Nov 2022, 06:00

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.

BlackVortex
Posts: 3
Joined: 30 Nov 2022, 04:32

Re: Script for hitting spacebar and button 1 for a game

Post by BlackVortex » 30 Nov 2022, 06:04

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.

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
[Mod edit: [code][/code] tags added.]

User avatar
mikeyww
Posts: 26437
Joined: 09 Sep 2014, 18:38

Re: Script for hitting spacebar and button 1 for a game

Post by mikeyww » 30 Nov 2022, 06:36

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.

Code: Select all

winTitle = ahk_exe notepad.exe

#If WinExist(winTitle)
^l::
ControlSend,, {Space}1
Return
#If
If you click on the posted commands, you can learn more about them.

Would try this without minimizing any windows.

BlackVortex
Posts: 3
Joined: 30 Nov 2022, 04:32

Re: Script for hitting spacebar and button 1 for a game

Post by BlackVortex » 30 Nov 2022, 07:34

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?

User avatar
mikeyww
Posts: 26437
Joined: 09 Sep 2014, 18:38

Re: Script for hitting spacebar and button 1 for a game

Post by mikeyww » 30 Nov 2022, 10:22

Yes. See :arrow: 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:

Code: Select all

#If WinExist("ahk_exe notepad.exe")
^l::
ControlSend,, {Space}1
Return
#If

Post Reply

Return to “Gaming Help (v1)”