Hi,
I have a mental block that needs a kick. I have a function that contains a loop terminated by a mouse click:
suspend, on
myFunction()
{
While, !(GetKeyState("LButton", "p"))
{
<do stuff that takes time>
}
}
suspend, off
The LButton is used as a hotkey for other things that are running at the same time, hence the use of suspend. The problem with this approach is that the mouse click is sampled once per loop which allows it to be missed. The user must click multiple times or hold it down for it to be recognized. Looking for it inside the loop just slows things down. Since I'm in a function it is not convenient to use the hotkey command with an associated label.
What's the best way to handle such a situation?
Relayer
Capture keypress in a function
Re: Capture keypress in a function
you could use a global variable with a hotkey. Hotkey simply sets it to 0 and when the loop starts all over, the variable is checked. Since the variable is already at 0 now, the loop exits. It goes somewhere along the lines of
Code: Select all
Gvar := 1
LButton::
GVar := 0
return
MyFunction()
{
global GVar
while(GVar)
stuffs
}
Try out CMD class
Re: Capture keypress in a function
Thank you Ronins!
I had considered that but my function is part of a class library. I want to do this in a way that the host script doesn't need to know anything about what the class function is doing. Your solution requires the host script to set the global variable as part of the hotkey routine.
There may not be an easy way to do this.
Relayer
I had considered that but my function is part of a class library. I want to do this in a way that the host script doesn't need to know anything about what the class function is doing. Your solution requires the host script to set the global variable as part of the hotkey routine.
There may not be an easy way to do this.
Relayer
Re: Capture keypress in a function
You can use the Hotkey command to dynamically register a ~LButton hotkey. To avoid modifying some other LButton hotkey, you can use #if/#ifwin with a condition which is unique but always true.