Wait for mouse button to be released

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
kpassaur
Automation Wizard
Posts: 662
Joined: Wed Jul 07, 2004 1:55 pm

Wait for mouse button to be released

Post by kpassaur » Fri May 24, 2019 1:09 pm

I know how to use WaitKeyDown>VK1 but is there a way to determine when it has been released?

User avatar
JRL
Automation Wizard
Posts: 3276
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: Wait for mouse button to be released

Post by JRL » Fri May 24, 2019 9:03 pm

Here is one way to capture mouse button release. I think there is a Microsoft API that I've tried but this usually works and is something I can remember. Basically, make a transparent dialog that covers the screen. And use the built in "MouseUp" dialog event handler. In this example I placed the dialog at 0,0 and made the dialog size 10,000 x 10,000 pixels which is way larger than my screen area so it covers everything. You are likely aware of smarter ways to acquire total screen area then make the dialog that exact size.

If you need to use the mouse click on the underlying screen you'll need to capture the coordinates and use them after the dialog has closed. Usually you'll want the mouse position when the mouse is clicked as well. That can be easily captured using a "MouseDown" dialog event handler.

Be sure you close the dialog or you lose your screen to it. If you forget, not a big problem, you can always close the dialog by clicking on it then pressing ALT + F4


Code: Select all

Dialog>Dialog1
object Dialog1: TForm
  Color = 16711808
  BorderStyle = bsNone
  TransparentColor = True
  TransparentColorValue = 16711808
end
EndDialog>Dialog1

AddDialogHandler>Dialog1,,OnMouseUp,MouseUp

Let>WIN_USEHANDLE=1
  MoveWindow>Dialog1.handle,0,0
  ResizeWindow>Dialog1.handle,10000,10000
Let>WIN_USEHANDLE=0

Show>dialog1,

SRT>MouseUp
  CloseDialog>Dialog1
  MDL>mouse is released%crlf%Screen is unblocked
END>MouseUp

kpassaur
Automation Wizard
Posts: 662
Joined: Wed Jul 07, 2004 1:55 pm

Re: Wait for mouse button to be released

Post by kpassaur » Sat May 25, 2019 3:37 pm

Thanks I'll give it a try.

Post Reply