Reset GetAsyncKeyState()?

Windows specific forum
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Reset GetAsyncKeyState()?

Post by IdeasVacuum »

I need to collect 2 or more points from anywhere on screen (on the desktop or any app window).

With GetAsyncKeyState_(#VK_LBUTTON) & 32768 I can get the first point from the first mouse left button down, but then that button state is still true when I want to pick the next point, so I don't get the chance to pick:

Code: Select all

Global igpt1.POINT, igpt2.POINT

   Repeat
             If(GetAsyncKeyState_(#VK_ESCAPE) & 32768)
                     Debug "#VK_ESCAPE ALL"
                     Goto Quit

             ElseIf(GetAsyncKeyState_(#VK_LBUTTON) & 32768) ;button is down
                     Debug "Left Down Pt1"
                     GetCursorPos_(igpt1)
                     iPick1 = #True
                     Break
             EndIf

   Until iPick1 = #True

   Repeat
             If(GetAsyncKeyState_(#VK_ESCAPE) & 32768)
                     Debug "#VK_ESCAPE LOOP 2"
                     Goto Quit

             ElseIf(GetAsyncKeyState_(#VK_LBUTTON) & 32768) ;button is down
                     Debug "Left Down Pt2"
                     GetCursorPos_(igpt2)
                     iPick2 = #True
                     Break
             EndIf

   Until iPick2 = #True

Quit:

End
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Reset GetAsyncKeyState()?

Post by IdeasVacuum »

Well, this seems to work:

Code: Select all

Global igpt1.POINT, igpt2.POINT

Global  MouseUp.INPUT
        MouseUp\type = #INPUT_MOUSE
        MouseUp\mi\dx = 0
        MouseUp\mi\dy = 0
        MouseUp\mi\mouseData = 0
        MouseUp\mi\dwFlags = #MOUSEEVENTF_LEFTUP
        MouseUp\mi\time = 0
        MouseUp\mi\dwExtraInfo = 0


   SendInput_(1,@MouseUp,SizeOf(INPUT))

   Repeat
             If(GetAsyncKeyState_(#VK_ESCAPE) & 32768)
                     Debug "#VK_ESCAPE ALL"
                     Goto Quit

             ElseIf(GetAsyncKeyState_(#VK_LBUTTON) & 32768) ;button is down
                     Debug "Left Down Pt1"
                     GetCursorPos_(igpt1)
                     Debug "x: " + Str(igpt1\x) + " y: " +  Str(igpt1\y)
                     iPick1 = #True
                     Break
             EndIf

   Until iPick1 = #True

   SendInput_(1,@MouseUp,SizeOf(INPUT))
   ;mouse_event_(#MOUSEEVENTF_LEFTUP,0,0,0,0)

   Repeat
             If(GetAsyncKeyState_(#VK_ESCAPE) & 32768)
                     Debug "#VK_ESCAPE LOOP 2"
                     Goto Quit

             ElseIf(GetAsyncKeyState_(#VK_LBUTTON) & 32768) ;button is down
                     Debug "Left Down Pt2"
                     GetCursorPos_(igpt2)
                     Debug "x: " + Str(igpt2\x) + " y: " +  Str(igpt2\y)
                     iPick2 = #True
                     Break
             EndIf

   Until iPick2 = #True

Quit:

End
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Reset GetAsyncKeyState()?

Post by Kwai chang caine »

Justly i need this code now, works good :wink:
Thanks 8)
ImageThe happiness is a road...
Not a destination
breeze4me
Enthusiast
Enthusiast
Posts: 633
Joined: Thu Mar 09, 2006 9:24 am
Location: S. Kor

Re: Reset GetAsyncKeyState()?

Post by breeze4me »

works fine.

Code: Select all

Global igpt1.POINT, igpt2.POINT
GetAsyncKeyState_(#VK_ESCAPE)
GetAsyncKeyState_(#VK_LBUTTON)

   Repeat
             If(GetAsyncKeyState_(#VK_ESCAPE) & 32769 = 32769)
                     Debug "#VK_ESCAPE ALL"
                     Goto Quit

                   ElseIf(GetAsyncKeyState_(#VK_LBUTTON) & 32769 = 32769) ;button is down
                     ;GetAsyncKeyState_(#VK_LBUTTON)
                     Debug "Left Down Pt1"
                     GetCursorPos_(igpt1)
                     iPick1 = #True
                     Break
             EndIf

   Until iPick1 = #True

   Repeat
             If(GetAsyncKeyState_(#VK_ESCAPE) & 32769 = 32769)
                     Debug "#VK_ESCAPE LOOP 2"
                     Goto Quit

                   ElseIf(GetAsyncKeyState_(#VK_LBUTTON) & 32769 = 32769) ;button is down
                     ;GetAsyncKeyState_(#VK_LBUTTON)
                     Debug "Left Down Pt2"
                     GetCursorPos_(igpt2)
                     iPick2 = #True
                     Break
             EndIf

   Until iPick2 = #True

Quit:

End
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4946
Joined: Sun Apr 12, 2009 6:27 am

Re: Reset GetAsyncKeyState()?

Post by RASHAD »

My turn :)

Code: Select all

Global igpt1.POINT, igpt2.POINT
GetAsyncKeyState_(#VK_ESCAPE)
GetAsyncKeyState_(#VK_LBUTTON)

   Repeat
             If(GetAsyncKeyState_(#VK_ESCAPE) & 1)
                     Debug "#VK_ESCAPE ALL"
                     Goto Quit

                   ElseIf(GetAsyncKeyState_(#VK_LBUTTON) & 1) ;button is down
                     ;GetAsyncKeyState_(#VK_LBUTTON)
                     Debug "Left Down Pt1"
                     GetCursorPos_(igpt1)
                     Debug igpt1\x
                     Debug igpt1\y
                     iPick1 = #True
                     Break
             EndIf

   Until iPick1 = #True

   Repeat
             If(GetAsyncKeyState_(#VK_ESCAPE) & 1)
                     Debug "#VK_ESCAPE LOOP 2"
                     Goto Quit

                   ElseIf(GetAsyncKeyState_(#VK_LBUTTON) & 1) ;button is down
                     ;GetAsyncKeyState_(#VK_LBUTTON)
                     Debug "Left Down Pt2"
                     GetCursorPos_(igpt2)
                     Debug igpt2\x
                     Debug igpt2\y
                     iPick2 = #True
                     Break
             EndIf

   Until iPick2 = #True

Quit:

End

Egypt my love
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Reset GetAsyncKeyState()?

Post by IdeasVacuum »

Hmm. On my PC, both breeze4me and Rashad's snippets do not work entirely correctly - they both need a 'pre-click' before collecting the next two - in other words 3 clicks are required to collect the two point values...........
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4946
Joined: Sun Apr 12, 2009 6:27 am

Re: Reset GetAsyncKeyState()?

Post by RASHAD »

OK you are the boss
Try the next

Code: Select all

Global igpt1.POINT, igpt2.POINT
      If GetAsyncKeyState_(#VK_LBUTTON) & $8000 = 32768
         keybd_event_(#VK_LBUTTON, 0, 0, 0)
         keybd_event_(#VK_LBUTTON, 0,#KEYEVENTF_KEYUP, 0)
      EndIf 

   Repeat
             If(GetAsyncKeyState_(#VK_ESCAPE) & 1)
                     Debug "#VK_ESCAPE ALL"
                     Goto Quit

                   ElseIf(GetAsyncKeyState_(#VK_LBUTTON) & 1) ;button is down
                     ;GetAsyncKeyState_(#VK_LBUTTON)
                     Debug "Left Down Pt1"
                     GetCursorPos_(igpt1)
                     Debug igpt1\x
                     Debug igpt1\y
                     iPick1 = #True
                     Break
             EndIf

   Until iPick1 = #True

   Repeat
             If(GetAsyncKeyState_(#VK_ESCAPE) & 1)
                     Debug "#VK_ESCAPE LOOP 2"
                     Goto Quit

                   ElseIf(GetAsyncKeyState_(#VK_LBUTTON) & 1) ;button is down
                     ;GetAsyncKeyState_(#VK_LBUTTON)
                     Debug "Left Down Pt2"
                     GetCursorPos_(igpt2)
                     Debug igpt2\x
                     Debug igpt2\y
                     iPick2 = #True
                     Break
             EndIf

   Until iPick2 = #True

Quit:

End

Egypt my love
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Reset GetAsyncKeyState()?

Post by IdeasVacuum »

Ah no, the Mrs is the Boss :mrgreen:

Well, to my surprise, I get the same issue with your new code Rashad :shock: Also, I thought MS had superseded keybd_event with SendInput?
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
Post Reply