Sorry falls ich nerve.
Hab nun das Beispiel WindowedScreen.pb genommen und es dahin modifiziert das man mit der Rechten Maustaste die Maus wieder freigeben kann.
Unter Linux läuft der Code
Und unter Windows scheint es so als würde nach dem ersten Rechtsklick permant die Rechte Maustaste gedrückt werden.
Ich weiß nicht was ich da falsch mache. Für mich ist der Code logisch und richtig.
Zum Probieren muß der Code im Example Ordner gespeichert werden, damit der Pfad zum BMP passt.
ohne Screen immer GetAsyncKeyState_(#Button) verwenden.
(Linke Maustaste: #VK_LBUTTON, rechte: #VK_RBUTTON)
geht übrigens auch als Ersatz für die Keyboardbefehle. (#VK_A, usw.)
GetAsyncKeyState_(#Button) möchte ich nicht verwenden weil der Code auch unter Linux laufen soll
Vielen Dank schonmal.
GreyEnt
Code: Alles auswählen
;
; ------------------------------------------------------------
;
; PureBasic - Windowed Screen example file
; edit by GreyEnt
;
; (c) Fantaisie Software
;
; ------------------------------------------------------------
;
; Konstanten für Linux
;#Red=255
;#slash="/"
; Konstanten für Windows
#slash="\"
If InitSprite() = 0 Or InitKeyboard() = 0 Or InitMouse() = 0
MessageRequester("Error", "Can't open the sprite system", 0)
End
EndIf
If OpenWindow(0, 0, 0, 340, 285, "Gadget and sprites!", #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_ScreenCentered)
ButtonGadget(1, 10, 10, 100, 25, "Grab input")
ButtonGadget(2, 120, 10, 100, 25, "Button 2")
ButtonGadget(3, 230, 10, 100, 25, "Button 3")
TextGadget (4, 10, 40, 300, 30, "Press 'LeftMouse Button' to ungrab keyboard and mouse")
If OpenWindowedScreen(WindowID(0), 10, 70, 320, 200, 0, 0, 0)
LoadSprite(0, "Data"+#slash+"PureBasicLogo.bmp")
Else
MessageRequester("Error", "Can't open windowed screen!", 0)
End
EndIf
EndIf
direction = 1
playerX = 1
playerY = 1
Repeat
Repeat
; Always process all the events to flush the queue at every frame
Event = WindowEvent()
Select Event
Case #PB_Event_CloseWindow
Quit = 1
Case #PB_Event_Gadget
; Do the normal application management here
Gadget = EventGadget()
Select Gadget
Case 1
InputReleased = 0
ReleaseMouse(#False)
SetGadgetText(4, "Press 'LeftMouse Button' to ungrab keyboard and mouse")
Case 2, 3
SetGadgetText(4, "Button "+Str(Gadget)+" pressed.")
EndSelect
EndSelect
Until Event = 0 ; Quit the event loop only when no more events are available
If InputReleased = 0
ExamineMouse()
If MouseButton(#PB_MouseButton_Right)=1
ReleaseMouse(#True)
InputReleased = 1
SetGadgetText(4, "Press Button to grab keyboard and mouse")
EndIf
; do the sprite & screen management at every frame
ExamineKeyboard()
If KeyboardPushed(#PB_Key_Up) And playerY > 0 : playerY -3 : EndIf
If KeyboardPushed(#PB_Key_Down) And playerY < 280 : playerY +3 : EndIf
If KeyboardPushed(#PB_Key_Left) And playerX > 0 : playerX -3 : EndIf
If KeyboardPushed(#PB_Key_Right) And playerX < 300 : playerX +3 : EndIf
If KeyboardPushed(#PB_Key_F1)
ReleaseMouse(#True)
InputReleased = 1
SetGadgetText(4, "Press Button to grab keyboard and mouse")
EndIf
EndIf
; Clear the screen and draw our sprites
ClearScreen(RGB(0,0,0))
ClipSprite(0, 0, 0, x, x/8)
DisplaySprite(0, x, 100)
DisplaySprite(0, x, x)
DisplaySprite(0, 300-x, x)
DisplaySprite(0, playerX, playerY)
StartDrawing(ScreenOutput())
Line(MouseX()-5,MouseY(),10,0,#Red)
Line(MouseX(),MouseY()-5,0,10,#Red)
StopDrawing()
x + direction
If x > 300 : direction = -1 : EndIf ; moving back to the left with negative value
If x < 0 : direction = 1 : EndIf ; moving to the right with positive value
FlipBuffers() ; Inverse the buffers (the back become the front (visible)... and we can do the rendering on the back
Until Quit Or KeyboardPushed(#PB_Key_Escape)