New to coding in general can anyone help

Ask gaming related questions (AHK v1.1 and older)
Darkthornex
Posts: 6
Joined: 17 Nov 2017, 16:30

New to coding in general can anyone help

17 Nov 2017, 16:34

basically i want the timer to send my input thats also a part of my script


#Persistent
GoSub, MyTimer ;Call it once, then it sets it self to run every 300.0 to 500.0 seconds
return

MyTimer:
SendInput, {^a 1}
Random, Time_To_Wait, 300.0, 500.0 ;
SetTimer, MyTimer, % Time_To_Wait * -1000
return

^a::
Send, ,chop {enter 1}
Send, ,mine {enter 1}
Send, ,forage {enter 1}
Send, ,fish {enter 1}
return

^z::
Send, ,adv {enter 1}
Return

^x::
Send, ,heal auto {enter 1}
Send, ,pheal auto {enter 1}
Return

Esc::ExitApp
User avatar
Exaskryz
Posts: 2882
Joined: 17 Oct 2015, 20:28

Re: New to coding in general can anyone help

17 Nov 2017, 18:55

First off is that SendInput should be SendInput, ^a. If you want to use a multiple times and have it use Ctrl, it would be Send ^{a 4} or whichever number you'd like.

However, Would you like your timer MyTimer to execute the ^a hotkey? Normally AHK's SendInput does not do that. There is a way to do it with SendLevel, but I recommend a different way. You can use GoSub ^a to jump to the ^a hotkey -- Hotkeys are also labels.
Darkthornex
Posts: 6
Joined: 17 Nov 2017, 16:30

Re: New to coding in general can anyone help

17 Nov 2017, 21:17

#Persistent
GoSub, MyTimer ;Call it once, then it sets it self to run every 300.0 to 500.0 seconds
return

MyTimer:
SendInput, f12
Random, Time_To_Wait, 300.0, 500.0 ;
SetTimer, MyTimer, % Time_To_Wait * -1000 ;
return

f12::
Send, ,chop {enter 1}
Send, ,mine {enter 1}
Send, ,forage {enter 1}
Send, ,fish {enter 1}
return

would this work as a fix to my problem? having a one key input
to clarify what i want is for the timer to run the portion of my code once ever 5-8ish minutes
User avatar
Exaskryz
Posts: 2882
Joined: 17 Oct 2015, 20:28

Re: New to coding in general can anyone help

21 Nov 2017, 19:48

If it works, it works. In fact, a potential mistake I made is that SendInput can indeed trigger other hotkeys. Normally people don't want that to happen, and they make their hotkeys use the $ modifier or use #UseHook, but in this case, it might work. I tested it by changing the Time_To_Wait to be 3, 5 instead of 300.0, 500.0 so I could see it run quickly.

First thing you'd need to change is SendInput, {f12}. Otherwise it just sends, f, 1, and 2.

Second thing is I could not get the script to work. It did the normal F12 behavior in my editor, Notepad++, which was hiding the toolbars. It may still work for you; it may be that if any running AHK script uses the KeyBoard Hook (#InstallKeyBdHook) then all scripts do. I have multiple scripts running, so I may get a different result than if I closed all those scripts and ran just yours.

But if you replace SendInput {f12} with GoSub, f12, it should work reliably.

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: Xeokis and 90 guests