u/chaneg

Spamming right click with a modifier key.

I am trying to write what I thought was a very simple script.

While holding down backtick, ` i.e., vkC0, I want it to keep CTRL held down and spam right click. However, I always run into problems where either CTRL gets stuck held down, or the script keeps spamming after letting go of the key.

I have tried so many common variants using GetKeyState or keywait, but nothing seems to help.

One suggestion was to use this pattern:

~a::
	tooltip A PRESSED
	return

~a up::
	tooltip A RELEASED
	return

instead, but that still doesn't seem to work.

I've similarly found a comment that suggested this is the best pattern:

a::
	if (a_pressed)
		return
	a_pressed := 1
	; [...]
	return

a up::
	a_pressed := 0
	return

but it doesn't work for me either. This is a sample attempt in (which isn't ideal because I would prefer CTRL be held down the whole time I hold backtick down).

vkC0_pressed := 0

*vkC0::
    if (vkC0_pressed)
        return
    
    vkC0_pressed := 1
    SetTimer, SendRightClick, 50
return

*vkC0 up::
    SetTimer, SendRightClick, Off
    vkC0_pressed := 0
return

SendRightClick:
    SendInput ^{RButton}
return

There are other attempts, but I have so many failed attempts that I have completely lost track at this point. I have tried numerous variations of this in v1 and in v2, but I would prefer a v2 solution.

reddit.com
u/chaneg — 2 days ago