Page 1 of 1

keyboard events

Posted: Tue Aug 31, 2004 9:53 am
by waffle
Code updated For 5.20+

I had an odd bug and just figured out the problem,
and thought to share this :)

Code: Select all


If InitSprite() = 0 Or InitKeyboard() = 0
  MessageRequester("Header Error", "Can't open DirectX 7 or later", 0)
  End
EndIf
If OpenWindow(0,0,0,300,200, "bug test",#PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_TitleBar | #PB_Window_ScreenCentered)
  
  If OpenWindowedScreen(WindowID(0),0, 0, 300,200,0,0,0 )
    noquit=1
    While noquit
      we.l=WaitWindowEvent()
      ExamineKeyboard()
      If KeyboardPushed(#PB_Key_Escape)
        noquit=0
      EndIf
      key.s=KeyboardInkey()
      If key<>""
        Debug key
      EndIf
      Delay(1)
    Wend
  EndIf
EndIf
End

the bug is that pressing the keyboard does not
generate a window event and that took me awhile to
find out what was not happening :)

Probably a non issue when using gadgets though, as they
would detect keypresses themselves.

Re: keyboard events

Posted: Tue Aug 31, 2004 12:51 pm
by PB
> pressing the keyboard does not generate a window event

You can use the #WM_KEYDOWN event in a callback to catch keystrokes:

Code: Select all

Procedure MyWindowCallback(WindowID,Message,wParam,lParam)
  Result=#PB_ProcessPureBasicEvents
  If Message=#WM_KEYDOWN
    Debug "Asc = "+Str(wParam)
  EndIf
  ProcedureReturn Result
EndProcedure

If OpenWindow(0,100,150,400,200,#PB_Window_SystemMenu,"test")
  SetWindowCallback(@MyWindowCallback())
  Repeat
    ev=WaitWindowEvent()
  Until ev=#PB_EventCloseWindow
EndIf

Posted: Tue Aug 31, 2004 2:01 pm
by waffle
yea, that works too,
But I'm using a buffered screen anyway,
so i'm doing the old windowevent with the delay(1) thing.

Basically, I'm writing a map editor based on paul's tool
for hostile skys, only mine can import any bitmap
and has other features... any tile size and so on.

I may even add mouse support. So far it looks pretty good.

I'll place your code into my library.... it will get used :)

edit:
dropped in your code and also added mouse detection
so my map editor has full mouse support. Thanks again.