Help me ( basic script )

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
Nwb
Posts: 444
Joined: 29 Nov 2016, 08:56

Help me ( basic script )

29 Nov 2016, 09:06

Hello...
ok basically I just got to know about autohotkey from youtube
while I was searching for an autoclicker.

Anyways,
Now I want something that can click keys at specific time,
not mouse click.

Please help me.
I tried through the tutorial and tried to make a script.
But I just dont have enough experience.

So can anybody help me by making my script for me?

Ok here is the description:

Toggle key = F2.
Click F2 to start scriptm
and click F2 to stop script.

Click Esc to exit script. ( Pretty sure there was a way I forgot the script)

While F2,
Send the key S,
Send the key S

Sleep 1secound

Send the key W
Send the key W

Sleep 60secounds!

Loop script.

Secoundary condition:
1) I want the script to work on my game (Even when it is minimized)
Game name is : Minecraft.exe
2) If that is not possible.
I want the script to ONLY work on Minecraft.exe

Thanks alot for helping me guys.
I can never fully thank you. :thumbup:
I am your average ahk newbie. Just.. a tat more cute. ;)
User avatar
aztec3
Posts: 177
Joined: 07 Apr 2014, 12:05

Re: Help me ( basic script )

29 Nov 2016, 10:03

I don't have Minecraft on my system, so I can't be certain I have the correct class for it (used Minecraft), so that line might need to be changed based on what Window Spy might say. I start the program in PAUSE and use F2 to toggle UNPAUSE/PAUSE effect, ESC key will ExitApp. Give it a try and let me know.

UPDATE: Added the #IfWinActive statement inside the loop too.
UPDATE2: Changed last SLEEP from 1000 (1 second) to 60000 (60 seconds)

Code: Select all

; Program for Nwb by aztec3 Tuesday 2016-11-29 @ 10:00 EDT
; URL: https://autohotkey.com/boards/viewtopic.php?f=5&t=25047
; Filename: Nwb_Minecraft_20161129A.ahk
;
Pause ; Start the code in PAUSE mode
#IfWinActive, ahk_class Minecraft ; Make sure Minecraft application is active window
Loop ; Loop and send keys
	{
		#IfWinActive, ahk_class Minecraft ; Make sure Minecraft application is active window
		Send, S
		Send, S
		Sleep, 1000
		Send, W
		Send, W
		Sleep, 60000
	}
return
F2::Pause
Esc::ExitApp
Last edited by aztec3 on 29 Nov 2016, 12:42, edited 2 times in total.
User avatar
Nwb
Posts: 444
Joined: 29 Nov 2016, 08:56

Re: Help me ( basic script )

29 Nov 2016, 10:50

aztec3 wrote:I don't have Minecraft on my system, so I can't be certain I have the correct class for it (used Minecraft), so that line might need to be changed based on what Window Spy might say. I start the program in PAUSE and use F2 to toggle UNPAUSE/PAUSE effect, ESC key will ExitApp. Give it a try and let me know.

UPDATE: Added the #IfWinActive statement inside the loop too.

Code: Select all

; Program for Nwb by aztec3 Tuesday 2016-11-29 @ 10:00 EDT
; URL: https://autohotkey.com/boards/viewtopic.php?f=5&t=25047
; Filename: Nwb_Minecraft_20161129A.ahk
;
Pause ; Start the code in PAUSE mode
#IfWinActive, ahk_class Minecraft ; Make sure Minecraft application is active window
Loop ; Loop and send keys
	{
		#IfWinActive, ahk_class Minecraft ; Make sure Minecraft application is active window
		Send, S
		Send, S
		Sleep, 1000
		Send, W
		Send, W
		Sleep, 1000
	}
return
F2::Pause
Esc::ExitApp
Hey thanks for the help!

The pause did not work.
Idk why...
When I clicked F2 minecraft took a screenshot.
So I changed F2 with F in the script...

It still did not work.
I unpaused(manually) it and it worked.
can you replace that with toggle?

Also I noticed that the script would click on w key for in milisecounds.
So is there a way we can change that too?

I want script to do this:

Hold W(1secound)
Sleep 2secound
Hold S(1secound)
Sleep 20Secound.

Ty!
I am your average ahk newbie. Just.. a tat more cute. ;)
User avatar
Nwb
Posts: 444
Joined: 29 Nov 2016, 08:56

Re: Help me ( basic script )

29 Nov 2016, 10:51

Since it held W and S for milisecounds,
I could not crosscheck if the #IFWINACTIVE worked.
I am your average ahk newbie. Just.. a tat more cute. ;)
User avatar
aztec3
Posts: 177
Joined: 07 Apr 2014, 12:05

Re: Help me ( basic script )

29 Nov 2016, 11:00

So, you want to have the W and S keys HELD DOWN for 1 second, correct? 1000 milliseconds equals one second. Don't know why the F2 key is not working for you either, I tried it out (without the Minecraft line) and it worked. No problem adding delays, just want to make sure you want the keys held down for one second and you want the last sleep to be 20 seconds (first sleep is 2 seconds), correct?

Also, you can check in the IFWINACTIVE line works by trying to run the code in Notepad, no characters sent, then it works only in Minecraft.
User avatar
Nwb
Posts: 444
Joined: 29 Nov 2016, 08:56

Re: Help me ( basic script )

30 Nov 2016, 06:03

aztec3 wrote:So, you want to have the W and S keys HELD DOWN for 1 second, correct? 1000 milliseconds equals one second. Don't know why the F2 key is not working for you either, I tried it out (without the Minecraft line) and it worked. No problem adding delays, just want to make sure you want the keys held down for one second and you want the last sleep to be 20 seconds (first sleep is 2 seconds), correct?

Also, you can check in the IFWINACTIVE line works by trying to run the code in Notepad, no characters sent, then it works only in Minecraft.
Yeah.

And if that was the case in IFWINACTIVE it did not work.
I thaught IFWINACTIVE made so that the script runs even when the program is minimized and inactive( Meaning I use a browser while script
running in game for example)
I am your average ahk newbie. Just.. a tat more cute. ;)
User avatar
aztec3
Posts: 177
Joined: 07 Apr 2014, 12:05

Re: Help me ( basic script )

30 Nov 2016, 07:40

Nwb,
no, IfWinActive just checks to make sure the desired window (application) is active. I can't make it run in the background, it has to have control of the keyboard.

Try this then:

Code: Select all

; Program for Nwb by aztec3 Wednesday 2016-11-30 @ 07:39 EDT
; URL: https://autohotkey.com/boards/viewtopic.php?f=5&t=25047
; Filename: Nwb_Minecraft_20161129B.ahk
;
Pause ; Start the code in PAUSE mode
#IfWinActive, ahk_class Minecraft ; Make sure Minecraft application is active window
Loop ; Loop and send keys
	{
		#IfWinActive, ahk_class Minecraft ; Make sure Minecraft application is active window
		Send, {w down} ; w key held down
		Sleep, 2000 ; 2 second lapse
		Send, {w up} ; w key released
		Send, {s down} ; s key held down
		Sleep, 1000 ; 1 second delay
		Send, {s up} ; s key released
		Sleep, 20000 ; 20 second lapse
	}
return
F2::Pause
Esc::ExitApp
User avatar
Nwb
Posts: 444
Joined: 29 Nov 2016, 08:56

Re: Help me ( basic script )

30 Nov 2016, 09:26

aztec3 wrote:Nwb,
no, IfWinActive just checks to make sure the desired window (application) is active. I can't make it run in the background, it has to have control of the keyboard.

Try this then:

Code: Select all

; Program for Nwb by aztec3 Wednesday 2016-11-30 @ 07:39 EDT
; URL: https://autohotkey.com/boards/viewtopic.php?f=5&t=25047
; Filename: Nwb_Minecraft_20161129B.ahk
;
Pause ; Start the code in PAUSE mode
#IfWinActive, ahk_class Minecraft ; Make sure Minecraft application is active window
Loop ; Loop and send keys
	{
		#IfWinActive, ahk_class Minecraft ; Make sure Minecraft application is active window
		Send, {w down} ; w key held down
		Sleep, 2000 ; 2 second lapse
		Send, {w up} ; w key released
		Send, {s down} ; s key held down
		Sleep, 1000 ; 1 second delay
		Send, {s up} ; s key released
		Sleep, 20000 ; 20 second lapse
	}
return
F2::Pause
Esc::ExitApp
The pause does not work for me
cant I replace that with toggle?
I am your average ahk newbie. Just.. a tat more cute. ;)
User avatar
Nwb
Posts: 444
Joined: 29 Nov 2016, 08:56

Re: Help me ( basic script )

30 Nov 2016, 09:28

Exit also does not work.
Cant i replace that with emergancy exit script thing?
I am your average ahk newbie. Just.. a tat more cute. ;)
User avatar
aztec3
Posts: 177
Joined: 07 Apr 2014, 12:05

Re: Help me ( basic script )

30 Nov 2016, 10:01

Don't know why ESC to ExitApp isn't working for you...it does exit for me. As to toggle, alright, let's see if this is any better. If I comment out the IfWinActive, I can get it to "work" (used notepad to test characters sent and delay time), so this should ONLY work if Minecraft is the active window this runs in.

Code: Select all

; Program for Nwb by aztec3 Wednesday 2016-11-30 @ 10:00 EDT
; URL: https://autohotkey.com/boards/viewtopic.php?f=5&t=25047
; Filename: Nwb_Minecraft_20161130C.ahk
;
Pause ; Start the code in PAUSE mode
#IfWinActive, ahk_class Minecraft ; Make sure Minecraft application is active window
Loop ; Loop and send keys
	{
		#IfWinActive, ahk_class Minecraft ; Make sure Minecraft application is active window
		Send, {w down} ; w key held down
		Sleep, 2000 ; 2 second lapse
		Send, {w up} ; w key released
		Send, {s down} ; s key held down
		Sleep, 1000 ; 1 second delay
		Send, {s up} ; s key released
		Sleep, 20000 ; 20 second lapse
	}
return
;
F2::Pause, Toggle
;
Esc::
ExitApp

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Descolada, ntepa and 137 guests