How to disable repeat? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
mitz0029
Posts: 1
Joined: 22 Apr 2018, 11:35

How to disable repeat?

22 Apr 2018, 11:40

How to disable repeating numbers?

This is the code

$Xbutton2::
Random, rand, 7, 9
send %rand%
return

Thanks! Help ASAP! :bravo: :bravo:
Last edited by mitz0029 on 22 Apr 2018, 12:22, edited 1 time in total.
User avatar
evilC
Posts: 4823
Joined: 27 Feb 2014, 12:30

Re: How to disable repeat?

22 Apr 2018, 12:09

Mice buttons do not repeat when held, so no need for repeat suppression with mouse buttons.
For keyboard keys though, you need to use a variable. You can do repeat suppression with a KeyWait command, but it has side-effects if you do it with more than one key at once, so I advise against following any examples that use KeyWait or GetKeyState loops to achieve this.

Code: Select all

a_state:= 0
return

a::
	if (a_state)
		return
	a_state := 1
	; [Your code here]
	return

a up::
	a_state := 0
	return
User avatar
evilC
Posts: 4823
Joined: 27 Feb 2014, 12:30

Re: How to disable repeat?

22 Apr 2018, 12:38

Turns out he wanted non-repeating random numbers.

Solution:

Code: Select all

rand := RandomButNotLastNumber(7, 9)
Send % rand
return

RandomButNotLastNumber(min, max){
    static last := ""
    rand := last
    while (rand == last){ 
        Random, rand, % min, % max
    }
    last := rand
    return rand
}
[Edit] Fixed typos
Last edited by evilC on 23 Apr 2018, 06:00, edited 1 time in total.
SirRFI
Posts: 404
Joined: 25 Nov 2015, 16:52

Re: How to disable repeat?  Topic is solved

22 Apr 2018, 14:48

Turns out someone just asked me similar thing, apparently with the code above. I modified it for the answer before getting here though:

Code: Select all

values := []

Loop 10
	values.Push(RandomButNotLastNumber(1, 2))

output := ""
for key, val in values
	output .= key " = " val "`n"

MsgBox % output

RandomButNotLastNumber(min, max)
{
	static last := ""
	loop
	{
		Random, rand, %min%, %max%
		if (rand != last)
			break
	}
	last := rand
	return rand
}
Just a different approach for the same thing, with a test included.

EDIT: Provided further assistance via Discord.
Use

Code: Select all

[/c] forum tag to share your code.
Click on [b]✔[/b] ([b][i]Accept this answer[/i][/b]) on top-right part of the post if it has answered your question / solved your problem.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Mannaia666, ntepa, TAC109 and 254 guests