Page 1 of 1

ExamineKeyboard()

Posted: Thu Nov 17, 2005 3:37 pm
by nco2k
hi folks,

look at this:

Code: Select all

If InitSprite() And InitKeyboard() And OpenWindow(0, 0, 0, 640, 480, #PB_Window_SystemMenu | #PB_Window_ScreenCentered, "test") And OpenWindowedScreen(WindowID(0), 0, 0, 640, 480, 0, 0, 0) 
  
  Repeat 
    WinEvent.l = WindowEvent() 
    If WinEvent = 0 
      Delay(1) 
    EndIf 
    ExamineKeyboard() 
  Until WinEvent = #PB_Event_CloseWindow Or KeyboardReleased(#PB_Key_Escape) 
  
EndIf 

End
1.) push and hold down the escape key
2.) switch to another app due alt+tab or mouseclick, so that our app becomes inactive, but dont release the escape key
3.) switch back to our app due alt+tab or mouseclick, so that our app becomes active again

now the app will close because our app thinks the escape key was released, while we are stil holding down the escape key.

try this, with and without ExamineKeyboard(). without ExamineKeyboard() it works the way it should, like in every non-pb game.

Code: Select all

If InitSprite() And InitKeyboard() And OpenWindow(0, 0, 0, 640, 480, #PB_Window_SystemMenu | #PB_Window_ScreenCentered, "test") And OpenWindowedScreen(WindowID(0), 0, 0, 640, 480, 0, 0, 0) 
  
  Repeat 
    WinEvent.l = WindowEvent() 
    If WinEvent = 0 
      Delay(1) 
    EndIf 
    
    If GetForegroundWindow_() = WindowID(0) 
      ;ExamineKeyboard() 
      If KeyEscape = #True 
        If GetAsyncKeyState_(#VK_ESCAPE) = #False 
          Break 
        EndIf 
      ElseIf GetAsyncKeyState_(#VK_ESCAPE) 
        KeyEscape = #True 
      EndIf 
    EndIf 
    
  Until WinEvent = #PB_Event_CloseWindow 
  
EndIf 

End
edit: its also the same of course with KeyboardPushed():

Code: Select all

If InitSprite() And InitKeyboard() And OpenWindow(0, 0, 0, 640, 480, #PB_Window_SystemMenu | #PB_Window_ScreenCentered, "test") And OpenWindowedScreen(WindowID(0), 0, 0, 640, 480, 0, 0, 0)
  
  Repeat
    
    If GetForegroundWindow_() = WindowID(0)
      ExamineKeyboard()
      If KeyEscape = #True
        If KeyboardPushed(#PB_Key_Escape) = #False
          Break
        EndIf
      ElseIf KeyboardPushed(#PB_Key_Escape)
        KeyEscape = #True
      EndIf
    EndIf
    
    WinEvent.l = WindowEvent()
    If WinEvent = 0
      Delay(1)
    EndIf
    
  Until WinEvent = #PB_Event_CloseWindow
  
EndIf

End
c ya,
nco2k

Posted: Mon Dec 12, 2005 1:31 pm
by Fred
Seems like to be a directinput issue, as for some strange reasons, the key buffer takes some time to resynchronize, so we lost the state.