Page 1 of 1
Mouse trouble
Posted: Sat Feb 03, 2007 7:27 pm
by Matt
I'm having a little trouble with getting mouse events, since only MouseButton is the only function I see that PureBasic has...
I need to check whether the left mouse button was clicked, the right mouse button was clicked, if the left mouse button is being pressed, and if the right mouse button is being pressed.
I'm having a little trouble doing those things, of course I am able to use MouseButton to check whether they are being pressed, but what about being clicked?
Posted: Sat Feb 03, 2007 7:35 pm
by Derek
You will need to code your own routine if you are using a fullscreen, I think.
Posted: Sat Feb 03, 2007 7:38 pm
by Matt
Yeah I'm using full screen
Posted: Sat Feb 03, 2007 7:41 pm
by Derek
I assume you have some kind of gadgets to click on or something, are you asking for double clicks or just straight forward clicking on an object kind of thing?
Posted: Sat Feb 03, 2007 7:49 pm
by Matt
There will be a sprite taking up the whole screen in the full screen mode.
Posted: Sat Feb 03, 2007 8:18 pm
by Derek
You can always count how long the mousebutton has been down.
Try this.
Code: Select all
InitSprite()
InitMouse()
InitKeyboard()
OpenWindow(0,0,0,800,200,"")
OpenWindowedScreen(WindowID(0),0,0,800,200,0,0,0)
ticks=0
flag=0
ExamineKeyboard()
While Not KeyboardPushed(#PB_Key_Escape)
WaitWindowEvent()
Delay(1)
ExamineMouse()
If MouseButton(#PB_MouseButton_Left)=1
ticks+1
flag=1
EndIf
If MouseButton(#PB_MouseButton_Left)=0
If flag=1
If ticks<6
Debug "Clicked"
Else
Debug "Held down"
EndIf
flag=0
ticks=0
EndIf
EndIf
ExamineKeyboard()
Wend
Posted: Sat Feb 03, 2007 8:21 pm
by Matt
-edit-
thank you, this works perfect

Posted: Sat Feb 03, 2007 8:24 pm
by Derek
Your welcome.
Posted: Sat Feb 03, 2007 8:34 pm
by Matt
To suit what I needed I also needed to figure out when it was starting to be pressed.
So here is what I added, in case anybody would like to know.
Thanks again Derek
Code: Select all
InitSprite()
InitMouse()
InitKeyboard()
OpenWindow(0,0,0,800,200,"")
OpenWindowedScreen(WindowID(0),0,0,800,200,0,0,0)
ticks=0
flag=0
pressed=0
ExamineKeyboard()
While Not KeyboardPushed(#PB_Key_Escape)
WaitWindowEvent()
Delay(1)
ExamineMouse()
If MouseButton(#PB_MouseButton_Left)=1
ticks+1
flag=1
If ticks >= 200 And pressed = 0
Debug "left pressed"
pressed = 1
EndIf
EndIf
If MouseButton(#PB_MouseButton_Left)=0
If flag=1
If ticks<200
Debug "left clicked"
Else
Debug "left released"
EndIf
flag=0
ticks=0
pressed = 0
EndIf
EndIf
ExamineKeyboard()
Wend