PB 4.61 crazy, but working mouse code
Posted: Thu Jun 07, 2012 1:24 am
This example show how you can have a working mouse for a windowed application.
It circumvents the usual problems of grab/release for the mouse by not grabbing at all.
The crazy part here is , that ExamineMouse() is not called at at.
Disadvantage is that the system mouse cursor will stay.
Also note , that this method does not work under Windows.
Of course, you can still not read the mouse wheel or more than 2 buttons.
It circumvents the usual problems of grab/release for the mouse by not grabbing at all.
The crazy part here is , that ExamineMouse() is not called at at.
Disadvantage is that the system mouse cursor will stay.
Also note , that this method does not work under Windows.
Code: Select all
InitSprite()
InitKeyboard()
Define sp1
OpenWindow(0, 100, 100, 640, 480, "Window Moving Test")
OpenWindowedScreen(WindowID(0), 0, 0, 640, 480, 0, 0, 0)
If Not sp1
sp1 = CreateSprite(#PB_Any, 20, 20, #PB_Sprite_Texture)
If StartDrawing(SpriteOutput(sp1))
Box(0, 0, 20, 20, RGB(255, 0, 155))
Box(5, 5, 10, 10, RGB(155, 0, 255))
StopDrawing()
EndIf
EndIf
If InitMouse()
Repeat
Repeat
ev =WindowEvent()
Until ev = 0
i +1
mouse_x = WindowMouseX(0)
mouse_y = WindowMouseY(0)
mouse_button_left = MouseButton(#PB_MouseButton_Left)
mouse_button_right = MouseButton(#PB_MouseButton_Right)
ExamineKeyboard()
ClearScreen(RGB(0,0,0))
If IsSprite(sp1) And mouse_x > -1
DisplaySprite(sp1,mouse_x-10,mouse_y-10)
EndIf
FlipBuffers()
If KeyboardPushed(#PB_Key_Escape)
Break
EndIf
ForEver
Else
PrintN("Can't access mouse!")
EndIf