Page 1 of 1
Reset GetAsyncKeyState()?
Posted: Wed Aug 22, 2012 5:26 am
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
Re: Reset GetAsyncKeyState()?
Posted: Wed Aug 22, 2012 5:49 am
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
Re: Reset GetAsyncKeyState()?
Posted: Wed Aug 22, 2012 11:12 am
by Kwai chang caine
Justly i need this code now, works good
Thanks

Re: Reset GetAsyncKeyState()?
Posted: Wed Aug 22, 2012 11:53 am
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
Re: Reset GetAsyncKeyState()?
Posted: Wed Aug 22, 2012 1:06 pm
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
Re: Reset GetAsyncKeyState()?
Posted: Wed Aug 22, 2012 1:35 pm
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...........
Re: Reset GetAsyncKeyState()?
Posted: Wed Aug 22, 2012 1:47 pm
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
Re: Reset GetAsyncKeyState()?
Posted: Wed Aug 22, 2012 2:28 pm
by IdeasVacuum
Ah no, the Mrs is the Boss
Well, to my surprise, I get the same issue with your new code Rashad

Also, I thought MS had superseded keybd_event with SendInput?