Did it:)
This code switches modes from Windowed to Fullscreen and vice-versa.
I had problems doing this because switching modes somehow seemed to lock the keyboard buffer, resulting in an endless loop of mode switching.
I'm not sure if this is a PB bug, or a Windows feature.
Code: Select all
; Sample Code to Switch Screen Modes
; 2003/10/11
; Kenji Gunn
; Constants
#True = 1
#False = 0
#Screen_Width.w = 320
#Screen_Height.w = 240
#Screen_Depth.b = 16
; Variables
Scan_Input_AltEnter.b = 0
Scan_Event_WindowEvent.w = 0
Screen_Fullscreen.b = 0
; Open Window
OpenWindow(0, 0, 0, #Screen_Width, #Screen_Height, #PB_Window_SystemMenu, "Hit Alt + Enter to Switch Screen Modes")
; Initialize DirectX
InitSprite()
InitKeyboard()
OpenWindowedScreen(WindowID(), 0, 0, 320, 240, 1, 0, 0)
Repeat
; Scan Key Presses and Window Events
ExamineKeyboard()
Scan_Input_AltEnter = ((KeyboardPushed(#PB_Key_LeftAlt) Or 0) Or (KeyboardPushed(#PB_Key_RightAlt) Or 0)) And (KeyboardPushed(#PB_Key_Return) Or 0)
Scan_Event_WindowEvent = WindowEvent()
; Switch Screen Modes
If Scan_Input_AltEnter = #True
If Screen_Fullscreen = #True
Screen_Fullscreen = #False
CloseScreen()
OpenWindow(0, 0, 0, #Screen_Width, #Screen_Height, #PB_Window_SystemMenu, "Hit Alt + Enter to Switch Screen Modes")
OpenWindowedScreen(WindowID(), 0, 0, #Screen_Width, #Screen_Height, 0, 0, 0)
ElseIf Screen_Fullscreen = #False
Screen_Fullscreen = #True
CloseWindow(0)
CloseScreen()
OpenScreen(#Screen_Width, #Screen_Height, #Screen_Depth, "Hit Alt + Enter to Switch Screen Modes")
EndIf
Repeat
ExamineKeyboard()
Scan_Input_AltEnter = ((KeyboardPushed(#PB_Key_LeftAlt) Or 0) Or (KeyboardPushed(#PB_Key_RightAlt) Or 0)) And (KeyboardPushed(#PB_Key_Return) Or 0)
Until Scan_Input_AltEnter = #True
EndIf
; Flip Buffers
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape) Or Scan_Event_WindowEvent = #PB_Event_CloseWindow
End
I solved the problem with this bit:
Code: Select all
Repeat
ExamineKeyboard()
Scan_Input_AltEnter = ((KeyboardPushed(#PB_Key_LeftAlt) Or 0) Or (KeyboardPushed(#PB_Key_RightAlt) Or 0)) And (KeyboardPushed(#PB_Key_Return) Or 0)
Until Scan_Input_AltEnter = #True
Wait until the keyboard buffer is unlocked:)
Thanks for all the advice
-Shopro