How to detect a mouse event click

New to FreeBASIC? Post your questions here.
Jermy
Posts: 6
Joined: Apr 12, 2016 10:29

How to detect a mouse event click

Postby Jermy » Sep 21, 2018 21:26

I want to create a program where I can use the mouse to click another window and then wait until the window closes to do follow-up actions.

Code: Select all


Dim vpoint as Point
 GetCursorPos(@vpoint)
 
Print vpoint.x
Print vpoint.y

Dim vhandle as HANDLE

vhandle=WindowFromPoint(vpoint)

Print vhandle



With the above code I can retrieve the window handle of each window by pressing enter every time, can this also be done with the left mouse button?

Thanks
grindstone
Posts: 582
Joined: May 05, 2015 5:35
Location: Germany

Re: How to detect a mouse event click

Postby grindstone » Sep 21, 2018 23:21

Code: Select all

#Include "windows.bi"

Dim vpoint as Point

Do
   Do 'wait for left mouse button to be pressed
      Sleep 1
   Loop Until GetAsyncKeyState(VK_LBUTTON)
   
   Do 'wait for left mouse button to be released
      Sleep 1
   Loop While GetAsyncKeyState(VK_LBUTTON)
   
   GetCursorPos(@vpoint)
    
   Dim vhandle as HANDLE
   
   vhandle=WindowFromPoint(vpoint)
   
   Locate 1,1,0
   Print vhandle;"    "
   Print vpoint.x;"  "
   Print vpoint.y;"  "
   
Loop

Return to “Beginners”

Who is online

Users browsing this forum: No registered users and 3 guests