Spam current pressed key-combos. Autorepeat.

Ask gaming related questions (AHK v1.1 and older)
alexdubovyckvideos
Posts: 9
Joined: 08 Apr 2018, 15:28

Spam current pressed key-combos. Autorepeat.

10 Apr 2018, 12:35

This ia a translation of this topic Help me plz.

Hello everyone. I love ahk, but by myself i`m cannot realise my idea. Need your help.

technical task:
If i press key "1" and when hold it, i wanna the nummber 1 to be infinitly spammed. Until i realese it. (OK i can do it like that)
example:

Code: Select all

/*
**************************************************************************************
цифра 1 vk31 
11111111111111
**************************************************************************************
*/
~vk31::
	loop
	{
	GetKeyState, ScrollLockState, ScrollLock, T
	if (ScrollLockState = "U") {
	break
	} 
	else
	{
	Send {vk31}
	Sleep, 20 ; Sleep for 20 msec
	GetKeyState, state, vk31, P
	if state = U  ; The key has been released, so break out of the loop.
	break
	}
	}
return
BUT...
)

My task for you is much harder.
I wanna to press key combo`s, spam a lot of keys and until it press it all of them are will be sended. Autorepeat pressed key`s.

I can spam separately but not simultaneously.
I can fix it - if i created a lot of ahk script`s and run them one by one.

I hope it will be easy like that:
This example is incorrect

Code: Select all

Key := % A_ThisHotKey %	
while GetKeyState(Key, "P")
	{
		Send %key% or %key-combos%
	}
return
eg2:
better but dont support combos:

Code: Select all

#Persistent ; may not actually be necessary...
Loop, 255
Hotkey, % "~" Format("vk{:x}",A_Index), pressed, On
return

pressed:
spamkey := GetKeyName(SubStr(A_ThisHotkey,2))
; Tooltip % "You pressed "  GetKeyName(SubStr(A_ThisHotkey,2))
Tooltip % spamkey

while GetKeyState(spamkey, "P")
{
Send %spamkey%
}
return
Last edited by alexdubovyckvideos on 10 Apr 2018, 15:14, edited 2 times in total.
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Spam current pressed key-combos. Autorepeat.

10 Apr 2018, 13:01

you cant do what you want with AHK_L, Loop and a single ahk script. your alternatives are as follows:

- use a bunch of SetTimers and offload the spamming to them
- use AHK_H(?, idk havent dabbled in it doing this)
- keep opening a separate ahk process per hotkey
alexdubovyckvideos
Posts: 9
Joined: 08 Apr 2018, 15:28

Re: Spam current pressed key-combos. Autorepeat.

10 Apr 2018, 14:40

- keep opening a separate ahk process per hotkey
yes i do. this is decision what works as i wannt but. This is very very uncomfortable to run for eg 20+ ahk.exe macros. and then stop all of them.

- use AHK_H(?, idk havent dabbled in it doing this)
waht is AHK_H? special Library?
can you give short, easy example for me.

- use a bunch of SetTimers and offload the spamming to them.
can you give short, easy example for me.
SetTimers i can google for myself. how to offload? (maybe set to 0)
it should react then i release button INSTANTLY, i thought on timer it will continue spam. when i do not preseed button.

up
i`m tried settimers, the same combo problem. only 1 key spam

Code: Select all

/*
Timers
123
#maxhotkeysperinterval 1
*/


$1::
{
SetTimer, label_1, 50
}
return


label_1:
while GetKeyState(1, "P")
{
Send 1
}
while GetKeyState(1, "U")
{
SetTimer, label_1, OFF
}
Return


$2::
{
SetTimer, label_2, 50
}
return

label_2:

while GetKeyState(2, "P")
{
Send 2
}
while GetKeyState(2, "U")
{
SetTimer, label_2, OFF
}
Return
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Spam current pressed key-combos. Autorepeat.

10 Apr 2018, 17:04

ahk_h is a fork of ahk implementing multithreading + some other added functionality

your settimers dont work because youre still using loops. only one loop can execute at a time

the goal of the settimers was to dispense with the loops altogether

Code: Select all

$1::SetTimer, Spam1, % (shouldSpam1 := !shouldSpam1) ? 50 : "Off"
$2::SetTimer, Spam2, % (shouldSpam2 := !shouldSpam2) ? 50 : "Off"

Spam1:
{
	Send, 1
return
}

Spam2:
{
	Send, 2
return
}

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: Draken and 62 guests