While prevents mouse button hotkeys from working

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
func
Posts: 47
Joined: 20 May 2016, 20:52

While prevents mouse button hotkeys from working

04 Nov 2018, 12:25

The below example code should work for everyone. Right clicking twice fast should show a popup menu with one entry labeled "Test". Clicking it runs a simple subroutine that sets WaitingForInput to 1, and enters a While loop. For some reason, this prevents my ~RButton:: hotkey from working, but the exact same code will work with another hotkey such as ~Space::, why is that?

EDIT: I Just confirmed LButton also doesn't work. It seems that a While loop somehow blocks Mouse button hotkeys, but not keyboard hotkeys.. I'm confused

Code: Select all

#SingleInstance, force
#Persistent
#NoEnv

WaitingForInput := 0

Menu, MyMenu, Add, Test, Test
return  

Test:
    WaitingForInput := 1
    While (WaitingForInput = 1) {

    }
return

~Space::
~RButton::
    if (WaitingForInput = 1) {
        MsgBox Fired
	} else if (A_PriorHotKey = A_ThisHotKey and A_TimeSincePriorHotkey < 500) {
		Sleep 0
		Send {Esc}
		Menu, MyMenu, Show
	}
Return
func
Posts: 47
Joined: 20 May 2016, 20:52

Re: While prevents mouse button hotkeys from working

04 Nov 2018, 12:43

Problem solved. Needed to add #MaxThreadsPerHotkey 2 at the top of the script. If anyone can explain why this works please let me (and others) know.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: drani, montie and 224 guests