streaming keyboard input..missing?
Posted: Wed Jul 28, 2010 7:50 am
Is it me or when you hold down on a key in PB it doesn't give input to the window? If this is true how are people doing games with this language?
http://www.purebasic.com
https://www.purebasic.fr/english/
Run this code from help, and hold down on any key. One character goes to it's input. This causes slow typing in a console I made, and I haven't even tested 3D control.PB wrote:What do you mean? Of course a window receives keyboard input. More info, please.
Code: Select all
If InitSprite() And InitKeyboard() And OpenScreen(800,600,16,"")
Repeat
FlipBuffers()
ClearScreen(RGB(0, 0, 0))
ExamineKeyboard()
FullText$ + KeyboardInkey() ; Add the new text to the current one (if any)
; If we press the 'Back' key, we will delete the last character
;
If KeyboardReleased(#PB_Key_Back)
FullText$ = Left(FullText$, Len(FullText$)-1)
EndIf
; Display the result
;
If StartDrawing(ScreenOutput())
DrawingMode(1)
FrontColor(RGB(128, 255, 0))
DrawText(20, 20, "Just type some text...:")
DrawText(20, 40, FullText$)
StopDrawing()
EndIf
Until KeyboardPushed(#PB_Key_Escape)
EndIf
Code: Select all
If InitSprite() And InitKeyboard() And OpenScreen(800,600,16,"")
Repeat
FlipBuffers()
ClearScreen(RGB(0, 0, 0))
ExamineKeyboard()
FullText$ + KeyboardInkey() ; Add the new text to the current one (if any)
; If we press the 'Back' key, we will delete the last character
;
If KeyboardPushed(#PB_Key_Back)
FullText$ = Left(FullText$, Len(FullText$)-1)
EndIf
; Display the result
;
If StartDrawing(ScreenOutput())
DrawingMode(1)
FrontColor(RGB(128, 255, 0))
DrawText(20, 20, "Just type some text...:")
DrawText(20, 40, FullText$)
StopDrawing()
EndIf
Until KeyboardPushed(#PB_Key_Escape)
EndIfI agree that it would be nice to have that functionality, but currently there is no other way if you use the keyboad lib. Have you done a search on the forums allready? chances are high someone else allready did it and shared it.ultralazor wrote:@Thorium:Which requires manually writing a entire input system for projects handling literally every single key and timing.
Thorium wrote:I agree that it would be nice to have that functionality, but currently there is no other way if you use the keyboad lib. Have you done a search on the forums allready? chances are high someone else allready did it and shared it.ultralazor wrote:@Thorium:Which requires manually writing a entire input system for projects handling literally every single key and timing.
QBASIC had support for DirectInput? I dont think so. Is just had the Input command thats the same in PureBasic on the console.ultralazor wrote: I think even older BASIC compilers had such a feature(QBASIC..omicron etc..)
What does what I'm talking about even remotely have to do with DirectX API? Yes I believe they did have a managed input buffer..Thorium wrote:QBASIC had support for DirectInput? I dont think so. Is just had the Input command thats the same in PureBasic on the console.ultralazor wrote: I think even older BASIC compilers had such a feature(QBASIC..omicron etc..)
To be honest if you are a experienced game developer you likely will find the need to make your own engines or use other engines than the ones included in PureBasic. I only can speak for 2D. The 2D stuff in PureBasic is pretty basic and very easy. It's more for beginners to get into game development. Experienced coders will likely need some more. From what i see, the focus of PureBasic is currently more on the core stuff. You can go pretty much low level with PureBasic and do all what you want by your own. There are no limitations, it's more a hybrid of C and BASIC than just BASIC.
Code: Select all
Global Int_Entry.s = "", Int_ScreenProc.l = #Null
Procedure.s Entry()
ProcedureReturn Int_Entry
EndProcedure
Procedure.l ClearEntry()
Int_Entry = "" : ProcedureReturn #True
EndProcedure
Procedure.l ScreenCallback(hWnd.l, uMsg.l, wParam.l, lParam.l)
Static Len.l = 0, Result = #Null
If uMsg = #WM_CHAR
If wParam = #BS
If Len > 0 : Int_Entry = Left(Int_Entry, Len - 1) : Len - 1 : EndIf
ElseIf wParam = #CR
Int_Entry = ""
ElseIf wParam >= $20
Int_Entry + Chr(wParam) : Len + 1
EndIf
Else
Result = CallWindowProc_(Int_ScreenProc, hWnd, uMsg, wParam, lParam)
EndIf
ProcedureReturn Result
EndProcedure
Procedure.l InitEntry()
Protected Result.l = #False
If ScreenID()
Result = SetWindowLongPtr_(ScreenID(), #GWL_WNDPROC, @ScreenCallback())
If Int_ScreenProc = #Null : Int_ScreenProc = Result : EndIf
EndIf
ProcedureReturn Result
EndProcedure
;;;;;;;;;;;;;;;;;;;;;
InitSprite() : InitKeyboard()
OpenScreen(1440,900,32,"")
InitEntry()
Repeat
ExamineKeyboard()
ClearScreen(#Black)
If StartDrawing(ScreenOutput())
St.s = Entry()
If (ElapsedMilliseconds()/240)%2 : St + "_" : EndIf
DrawText(10, 10, St, #White, #Black)
StopDrawing()
EndIf
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape)
CloseScreen()
End