Help, i Do'nt know

Ask gaming related questions (AHK v1.1 and older)
BrazilianHunter
Posts: 1
Joined: 20 Jan 2018, 13:35

Help, i Do'nt know

20 Jan 2018, 13:42

How to make a script to click a key 6 times?
User avatar
Gio
Posts: 1247
Joined: 30 Sep 2013, 10:54
Location: Brazil

Re: Help, i Do'nt know

20 Jan 2018, 14:30

Hello BrazilianHunter.

Welcome to the AutoHotkey Community forums.

You can use Loop command to repeat single-commands or blocks of code. Also, to send keystrokes, you can use the Send command.

See the example below on how to do it (the example will press the key j 6 times).

Code: Select all

Loop, 6
Send j
If you cannot see the effect in place here, it is because the key pressing happens as soon as you execute the script. If you wish the script to wait so that you open a a window or something like that, you can use Sleep command.

The example below waits 10 seconds before pressing the key j 6 times.

Code: Select all

Sleep, 10000
Loop, 6
Send j
If you need further help, feel free to post again. Also, check out our portuguese subforums if you are brazilian and wish to talk about AutoHotkey in portuguese.

Best wishes :thumbup:
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Help, i Do'nt know

20 Jan 2018, 16:29

check out our portuguese subforums if you are brazilian and wish to talk about AutoHotkey in portuguese.
Isn't he/she hunting Brazilians?? :o :shifty: :silent:
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Help, i Do'nt know

20 Jan 2018, 18:14

BoBo wrote:Isn't he/she hunting Brazilians?? :o :shifty: :silent:
:lol: :D :bravo: :beer:
User avatar
divanebaba
Posts: 805
Joined: 20 Dec 2016, 03:53
Location: Diaspora

Re: Help, i Do'nt know

20 Jan 2018, 19:08

I think BrazilianHunter wants to realize the following:

Code: Select all

$j::
sendinput jjjjjj
return
Or

Code: Select all

$j::
loop 6
{
	sendinput j
	sleep 100
}	
return
Pressing one times triggers six times.
Einfach nur ein toller Typ. :mrgreen:
garry
Posts: 3763
Joined: 22 Dec 2013, 12:50

Re: Help, i Do'nt know

21 Jan 2018, 05:29

found this , send also first ctrl / alt / win and then key
https://autohotkey.com/boards/viewtopic.php?f=5&t=41768

Code: Select all

;- https://autohotkey.com/boards/viewtopic.php?f=5&t=41768
;-----------------------------------------------------------
;- test example for f1 , send ctrl+a twice
;-  open notepad with text , then click F1 , mark all text blue , then remove with mouse click , and after 5 seconds mark it again

f1::
loop,2
{
sendKey("control", "a")
sleep,5000
}
return

f2:: sendKey("alt", "a")
f3:: sendKey("win", "r")
f4:: sendKey("shift", "s")
;--------------------------------------------------
sendKey(key1, key2){
	vk1 := format("vk{:x}", getKeyVK(key1))
	vk2 := format("vk{:x}", getKeyVK(key2))
	sendinput, {%vk1% down}{%vk2%}{%vk1% up}
	}
;=================================================

another example

Code: Select all

;https://autohotkey.com/boards/viewtopic.php?f=5&t=41768
;- user exaskryz
;- notepad test mark text and copy / paste

f1::
sendKey("^a")
sleep,1000
sendKey("^c")
;-- check before the right place of cursor
sleep,1000
sendKey("^v")
return
;------------------
sendKey(key){
	RegExMatch(key,"{(.*)}",match) ; this is for finding if we used a key like {Enter} or {Backspace} or {Numpad7}
	target_key:=match1
	;MsgBox % target_key
	If !target_key ; in this case, we did not use { } in the input as the output is blank.
        {
		target_key:=SubStr(key,0) ; so we know it's going to be a single character like "1" or "t"
		vk := "{" format("vk{:x}", getKeyVK(target_key))  ; we are adding the { and } in the output because it initially didn't have it
		sc := format("sc{:x}", getKeySC(target_key)) "}"
        }
    else
        {
        vk := format("vk{:x}", getKeyVK(target_key)) ; we do not add { and } because it is already there in KEY. target_key does not have { } because that is not what the getKeyVk/Sc functions expect.
        sc := format("sc{:x}", getKeySC(target_key))
        }
    output:=StrReplace(key,target_key,vk . sc) ; we take the key which could be +{Enter} or !a, replace it with the target word
	send, %output%
    }
;=====================================================================

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: ReyAHK and 78 guests