Script to press a key multiple times if i press that key Topic is solved

Ask gaming related questions (AHK v1.1 and older)
ArdisX

Script to press a key multiple times if i press that key

16 Jan 2016, 15:19

Basically I would need help with a script here, since im kinda newbie.
I would need a script that does the following
-If i press "3" it should press 3 times key "3" with maybe a delay inbetween that I can change around. After it it should press 1. So basically I press 3 -> it does 3 - 3 -3 - 1
-Same with key 4 and key 5 basically. Not sure if I can do it in 1 script or I need 3 scripts for it
Thanks alot <3
User avatar
tidbit
Posts: 1273
Joined: 29 Sep 2013, 17:15
Location: USA

Re: Script to press a key multiple times if i press that key

16 Jan 2016, 15:30

Not sure if I can do it in 1 script or I need 3 scripts for it
Can you please explain what makes you think you can only have 1 hotkey per file? this is a mildly frequent 'issue'. Perhaps you could shed some light on it.

From the tutorial section 2.3 https://autohotkey.com/docs/Tutorial.htm#s23
Multiple hotkeys/hotstrings per file

This, for some reason crosses some people's minds. So I'll set it clear: AutoHotkey has the ability to have as many hotkeys and hotstrings in 1 file as you want. Whether it's 1, or 3253 (or more).

Code: Select all

#i::
   run, http://www.google.com/
Return

^p::
   run, notepad.exe
Return

~j::
   send, ack
Return

:*:acheiv::achiev
::achievment::achievement
::acquaintence::acquaintance
:*:adquir::acquir
::aquisition::acquisition
:*:agravat::aggravat
:*:allign::align
::ameria::America
The above code is perfectly acceptable. Multiple hotkeys, multiple hotstrings. All in one big happy script file.
rawr. fear me.
*poke*
Is it December 21, 2012 yet?
ArdisX

Re: Script to press a key multiple times if i press that key

16 Jan 2016, 15:42

Hey, thanks for your reply
as I said I dont really have much knowledge about creating a script and so I didnt know if you could put them all into one.
Thanks for your reply tho.
Someone got an idea how I could make the script do what I described above?
Shadowpheonix
Posts: 1259
Joined: 16 Apr 2015, 09:41

Re: Script to press a key multiple times if i press that key

17 Jan 2016, 14:02

ArdisX wrote:Hey, thanks for your reply
as I said I dont really have much knowledge about creating a script and so I didnt know if you could put them all into one.
Thanks for your reply tho.
Someone got an idea how I could make the script do what I described above?
Scripts like the one you are requesting are extremely simple. Reading the Tutorial should tell you everything you need to know to create this type of script yourself. However, here's your script just in case the tutorial is too much for you...

Code: Select all

3::
Send 3
Sleep 500    ; This is a 0.5 second delay.  I chose that length just because I could.
Send 3
Sleep 250    ; This is a 0.25 second delay.  I chose that length just because I could.
Send 3
Sleep 400    ; This is a 0.4 second delay.  I chose that length just because I could.
Send 1
Return

4::
Send 4
Sleep 500    ; This is a 0.5 second delay.  I chose that length just because I could.
Send 4
Sleep 250    ; This is a 0.25 second delay.  I chose that length just because I could.
Send 4
Sleep 400    ; This is a 0.4 second delay.  I chose that length just because I could.
Send 1
Return

5::    ; I did this one without delays in it, just so you could see the difference.
Send 5551
Return

; And just for the fun if it, here's another way to do it without delays...
6::Send 6661
ArdisX

Re: Script to press a key multiple times if i press that key

19 Jan 2016, 01:03

Thanks for your help.
Although if i try to use your script and press for example "3", I only get an output of 1 and that repeatedly. Basically what I would need is that it only does it once whenever I press 3.
So if I press 3 it does 3 3 3 1 and then does nothing anymore till I press 3 again. If someone would help me I would be grateful
Shadowpheonix
Posts: 1259
Joined: 16 Apr 2015, 09:41

Re: Script to press a key multiple times if i press that key

21 Jan 2016, 10:27

ArdisX wrote:Thanks for your help.
Although if i try to use your script and press for example "3", I only get an output of 1 and that repeatedly. Basically what I would need is that it only does it once whenever I press 3.
So if I press 3 it does 3 3 3 1 and then does nothing anymore till I press 3 again. If someone would help me I would be grateful

That is exactly what the script I provided does. I tested the script before I posted it, and it works correctly. If you are seeing other behavior, then I can only assume you either have some other script interfering, or made an error when copying the code I provided.
User avatar
Exaskryz
Posts: 2882
Joined: 17 Oct 2015, 20:28

Re: Script to press a key multiple times if i press that key  Topic is solved

21 Jan 2016, 10:42

Try putting a $ modifier on all the hotkeys That is, make it $3::, $4::, $5::, and $6::. Otherwise, you can use the #UseHook directive.

The idea is that your hotkeys with the code Shadow posted are recursing. The Send 3 activates the 3:: hotkey again and again.

Edit: @Shadow, I can confirm that running your code as is gets me the same results as the OP. A string of "1"s appear when I hit "3".
Shadowpheonix
Posts: 1259
Joined: 16 Apr 2015, 09:41

Re: Script to press a key multiple times if i press that key

21 Jan 2016, 10:51

Now I am really confused. The script worked perfectly before I posted it (and was the only code I had running). However, I just tried it again after reading Exaskryz's post, and now I too am getting the repeating "1"s. Adding either the $ modifier, or the #UseHook directive fixes it.
Recca
Posts: 35
Joined: 18 Jan 2016, 21:44

Re: Script to press a key multiple times if i press that key

22 Jan 2016, 00:22

Maybe my script from this thread https://autohotkey.com/boards/viewtopic ... 19&t=13162 can help you
just comment out the other hotkeys and put this in
3=3,50,u|3,50,u|3,50,u|1,100,u
.

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: prototype_zero and 74 guests