How to make a repeating hotkey with some keys only pressed once?

Ask gaming related questions (AHK v1.1 and older)
crimson4649
Posts: 18
Joined: 23 Jul 2017, 06:04

How to make a repeating hotkey with some keys only pressed once?

31 Aug 2020, 14:18

Sorry for the poor topic description, but i don't know what to name it.
That said, this has most likely been answered before, but because I don't know what to look/search for, I'm forced to make a new topic.

To the issue!

I want to make a standard looping script while holding down a key.
But I want the script to only once send two keys once.
One key when the script starts, and one key when I let go of the hotkey.

Example:

Code: Select all

!q:: 
Loop
{
if not GetKeyState("q", "P") 
Break
Send {1}
Sleep 10
}
Return
But I want the script to also to press "A" once when the script start, and "B" only once when i let go of "Q"

Something like this ( but working :P )

Code: Select all

!q::
Send {a} ;; Just once, for when I activate the script, not repeating unless I let go of q, and press it again.
Loop
{
if not GetKeyState("q", "P") 
Break
Send {1}
Sleep 10
}
Send {b} ;; Only ever when I let go of "Q"
Return
I hope my example helps in describing what Im looking for.

Thanks in advanced.
Last edited by BoBo on 31 Aug 2020, 16:58, edited 1 time in total.
Reason: Moved to Gaming section.
User avatar
ositoMalvado
Posts: 183
Joined: 24 Dec 2019, 12:02
Contact:

Re: How to make a repeating hotkey with some keys only pressed once?

31 Aug 2020, 21:05

Try this!

Code: Select all

#NoEnv
Process, Priority, , H
SetBatchLines, -1
ListLines Off
#KeyHistory 0
SendMode Input
SetTitleMatchMode 2
SetTitleMatchMode Fast
SetKeyDelay, -1, -1, Play
SetMouseDelay, -1
SetWinDelay, 0
SetControlDelay, 0
SetDefaultMouseSpeed, 0
SetWorkingDir, A_ScriptDir
;SCRIPT OPTIMIZATION ABOVE

global DELAY:=1

!q::
	send a
	while getkeystate("q", "p"){
		Send 1
		Sleep DELAY
	}
	send b
Return

~q::return ;Avoid key malfunction
My WEB some useful stuff

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: mexican scientist and 60 guests