Page 1 of 1
Capturing mouse events
Posted: Tue Sep 27, 2005 2:36 pm
by fenyctis
I would like to capture mouse events such as clicking in general, not only inside my window. I have tried the API command GetAsyncKeyState(2) (rightmouse down) but it would only work inside my own window as well.
Thanks in advance!
fenyctis
Posted: Tue Sep 27, 2005 3:22 pm
by Jellybean
Let me have a guess: You're checking it inside an event loop using WaitWindowEvent()?
Posted: Tue Sep 27, 2005 4:15 pm
by fenyctis
Err.. yes. Sounds like that's wrong.

Should I make a thread?
Posted: Tue Sep 27, 2005 4:24 pm
by netmaestro
I'd avoid threads if you don't need them. All you need to really do here is drop the wait from your windowevent check.
Code: Select all
.
.
Event = WindowEvent() ; not WaitWindowEvent() !
If Event
TurnPurple
Else
If GetAsyncKeyState(#PB_VerySpecificKey) ;numbers alone are less readable later
BlinkTwiceRapidly
ClearYourThroatLoudly
Else
Delay (10)
Endif
Endif
; Note: Some syntax in this program will not be available until PB 4.x
Posted: Tue Sep 27, 2005 4:36 pm
by fenyctis
I seem to have got it to work now. Thanks a bundle. But now I've got a 50% usage of my program. Is this because of the GetAsyncKeyState? Is there a way to prevent this?
Posted: Tue Sep 27, 2005 4:43 pm
by netmaestro
GetAsyncKeyState takes nanoseconds. Just make sure that if you don't have an event of some description to respond to that you put a decent-size delay in the code. 10 should be about right.
Posted: Tue Sep 27, 2005 4:44 pm
by fenyctis
Code: Select all
eid.l = WindowEvent()
If eid
If eid = #PB_Event_CLosewindow
quit = 1
EndIf
Else
If GetAsyncKeyState_(#VK_LBUTTON)
leftmousepressed = 1
Else
If leftmousepressed = 1
TriggerMouseReleaseAndBounceAround
leftmousepressed = 0
EndIf
EndIf
EndIf
Posted: Tue Sep 27, 2005 4:45 pm
by fenyctis
Okay.
--
Got it working, thanks a bundle.