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?
Mouse trouble
You can always count how long the mousebutton has been down.
Try this.
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
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
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

