ExamineKeyboard()

Just starting out? Need help? Post your questions and find answers here.
User avatar
nco2k
Addict
Addict
Posts: 1344
Joined: Mon Sep 15, 2003 5:55 am

ExamineKeyboard()

Post 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
If OSVersion() = #PB_OS_Windows_ME : End : EndIf
Fred
Administrator
Administrator
Posts: 18210
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post 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.
Post Reply