Page 1 of 1
Alt + Enter
Posted: Mon Oct 06, 2003 10:25 am
by Shopro
Hello,
Is there a easy way to switch from windowed screen to full screen mode with a "Alt + Enter"? This is my code, which doesn't work. pls do not run it, for it switches to and forth from windowed and fullscreen at great speed, and doesn't let you quit.
Code: Select all
ExamineKeyboard()
Input_Alt_Enter = ((KeyboardPushed(#PB_Key_LeftAlt) Or 0) Or (KeyboardPushed(#PB_Key_RightAlt) Or 0)) And (KeyboardPushed(#PB_Key_Return) Or 0)
If Input_Alt_Enter = 1
If FullScreen = 1
FullScreen = 0
CloseScreen()
OpenWindow(0, 0, 0, #Screen_Width, #Screen_Height, #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget | #PB_Window_ScreenCentered, #General_Title$)
OpenWindowedScreen(WindowID(), 0, 0, #Screen_Width, #Screen_Height, 1, 0, 0)
Load_Sprites()
Input_Alt_Enter = 0
ElseIf FullScreen = 0
FullScreen= 1
CloseWindow(0)
CloseScreen()
OpenScreen(#Screen_Width, #Screen_Height, 16, #General_Title$)
Load_Sprites()
Input_Alt_Enter = 0
EndIf
EndIf
Any advice will be appreciated
-Shopro
Re: Alt + Enter
Posted: Mon Oct 06, 2003 5:16 pm
by Ralf
purebasic dont suppot DOS coding where it was possible to switch by alt+return... you can swap screens by pressing alt+tab (standard on win)
Posted: Mon Oct 06, 2003 5:45 pm
by Proteus
Shopro, did you put examinekeyboard() inside the loop?
Ralf, Alt+Tab switches programs...
Posted: Mon Oct 06, 2003 8:58 pm
by Shopro
thanks for the replies,
Ralf:
I'm manualy trying to do that. Pls look at this code then:
Code: Select all
OpenWindow(0, 0, 0, 320, 240, #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget | #PB_Window_ScreenCentered, "Alt + Enter Input Test")
InitSprite()
InitKeyboard()
OpenWindowedScreen(WindowID(), 0, 0, 320, 240, 1, 0, 0)
Repeat
ExamineKeyboard()
Scan_WindowEvent = WindowEvent()
Input_Alt_Enter = ((KeyboardPushed(#PB_Key_LeftAlt) Or 0) Or (KeyboardPushed(#PB_Key_RightAlt) Or 0)) And (KeyboardPushed(#PB_Key_Return) Or 0)
StartDrawing(ScreenOutput())
DrawText(Str(Input_Alt_Enter))
StopDrawing()
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape) Or Scan_WindowEvent = #PB_Event_CloseWindow
This code returns 1 if Alt and Enter are pressed at the same time. It's the bit with the mode changing I am having trouble with.
Proteus:
yup, sure have:)
Posted: Fri Oct 10, 2003 7:37 pm
by Shopro
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