Create a loop or auto-typing function.

Ask gaming related questions (AHK v1.1 and older)
moisesp4
Posts: 4
Joined: 15 Jun 2021, 17:55

Create a loop or auto-typing function.

15 Jun 2021, 20:22

Hello. Good afternoon / morning everyone. I come to ask this community here, to see if they can help me to make a small function for "Autohotkey", I emphasize that I do not know much about this programming language, autohotkey. Without further ado, this is my problem:

I regularly play online / multiplayer games constantly, and I came up with the idea to make a function in autohotkey to gain Experience, money or anything of value in said game while I am sleeping or while I am doing something else on the computer. My idea is to create such a loop that makes in-game automatic keyboard keystrokes exclusively. Well, to clarify certain things, I explain how I want it to be developed.

"press: enter" (10s) - >>> "press: n" (7s) - >>> "press: p" (10s) - >> "hold down: W" (leave key pressed for 3s). * Repeat function *

And finally, an on and off to the script.

I do not know if I explained at all, but hey. Are there chances you will help me create this? Is it possible to create this loop ?, I hope you help me, thank you very much in advance.

I hope I'm not exaggerating a bit with what I'm asking ^^. :dance:
Last edited by moisesp4 on 17 Jun 2021, 13:33, edited 1 time in total.
User avatar
mikeyww
Posts: 26848
Joined: 09 Sep 2014, 18:38

Re: Create a loop or auto-typing function.

15 Jun 2021, 20:40

Code: Select all

#MaxThreadsPerHotkey 5
Global on
F3::
on := !on
While on
 press("Enter", 10), press("n", 7), press("p", 10), press("w", 3)
Return

press(key, sec) {
 If !on
  Return
 Send {%key% down}
 Loop, %sec%
  Sleep, 1000 * on
 Send {%key% up}
}
moisesp4
Posts: 4
Joined: 15 Jun 2021, 17:55

Re: Create a loop or auto-typing function.

17 Jun 2021, 13:49

Thank you very much for making this script. I tried to modify it, but the function gives me an error; the function does not do the repetition / looping in particular, the direction keys do not work, the function does not take more time than what you assign

This is the modification I made:

Code: Select all

#MaxThreadsPerHotkey 5

Global on
l:: send /cosechar
k:: send /atp
esc::exitapp
F3::
on := !on
While on
 press("Enter", 9), press("t", 2), press("l", 2), press("Enter", 2), press("p", 3), press("p", 3), press("p", 3), press("p", 3), press("p", 3), press("p", 3), press("p", 3), press("p", 3), press("p", 2), press("t", 2), press("k", 2), press("Enter", 3) 
Return

press(key, sec) {
 If !on
  Return
 Send {%key% down}
 Loop, %sec%
  Sleep, 1000 * on
 Send {%key% up}
}
[Mod edit: [code][/code] tags added.]

Thank you very much in advance for your help.
User avatar
mikeyww
Posts: 26848
Joined: 09 Sep 2014, 18:38

Re: Create a loop or auto-typing function.

17 Jun 2021, 17:39

What actually happens when you run this script in Notepad (i.e., triggering while Notepad is the active window)? What should happen instead? What error message appears for you?
moisesp4
Posts: 4
Joined: 15 Jun 2021, 17:55

Re: Create a loop or auto-typing function.

17 Jun 2021, 18:51

Excuse me, I did not understand your question very well. 1.-The error I get is that the Loop that I should do does not make it complete, The script begins its normal route, but ... when it goes to repeat (second repetition of the loop) a function is skipped (It skips " press ("Enter", 10) "). 2.- The time assigned to the functions does not match, they take longer than assigned (press ("t", 2) <- It takes longer than assigned). That's all. I go back and repeat, thank you very much for your help.
User avatar
mikeyww
Posts: 26848
Joined: 09 Sep 2014, 18:38

Re: Create a loop or auto-typing function.

17 Jun 2021, 20:06

I understand that you are testing how your script performs while in Notepad. I am looking at the script that you posted. I see nothing that says, "Enter", 10. When you say that the press takes longer than assigned, how long does it take? How did you determine the duration?
moisesp4
Posts: 4
Joined: 15 Jun 2021, 17:55

Re: Create a loop or auto-typing function.

17 Jun 2021, 22:44

Excuse my mistake, I meant {"Enter", 9}. But tell me, do you understand a little what I'm giving myself to describe? It would be useful for you to tell me if you are understanding something of what I am saying, and so I explain any doubts you may have. About how I reptify and verify the duration of the second assignments that I put to such a function, "I add up all the assigned seconds of the functions in a calculator" or I just mentally check them haha, some are not necessary to check so much to know if the assigned seconds they are being fulfilled successfully.
iamkajal
Posts: 4
Joined: 10 Jun 2021, 21:38

Re: Create a loop or auto-typing function.

18 Jun 2021, 02:11

Use hotkey() function to press the combination of keys like ctrl-c, ctrl-a, etc.

Code: Select all

import pyautogui
pyautogui.hotkey("ctrlleft", "a")
User avatar
mikeyww
Posts: 26848
Joined: 09 Sep 2014, 18:38

Re: Create a loop or auto-typing function.

18 Jun 2021, 06:51

The script worked, but perhaps it is not doing what you need it to do. Perhaps you can explain what you meant when you wrote:

press: enter (10s)

As you can see, the current script holds the key down for that amount of time.

If needed, you can add some commands with A_TickCount to track the time and then compute time elapsed at any point.

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: No registered users and 37 guests