streaming keyboard input..missing?
- ultralazor
- Enthusiast

- Posts: 186
- Joined: Sun Jun 27, 2010 9:00 am
streaming keyboard input..missing?
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?
so many ideas so little time..
Re: streaming keyboard input..missing?
What do you mean? Of course a window receives keyboard input. More info, please.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
"PureBasic won't be object oriented, period" - Fred.
- ultralazor
- Enthusiast

- Posts: 186
- Joined: Sun Jun 27, 2010 9:00 am
Re: streaming keyboard input..missing?
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
so many ideas so little time..
Re: streaming keyboard input..missing?
I'm not a fast typer but does it type faster if you turn off the debugger? Also, here's how to make the backspace faster.
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)
EndIfwww.posemotion.com
PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef
Even the vine knows it surroundings but the man with eyes does not.
PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef
Even the vine knows it surroundings but the man with eyes does not.
Re: streaming keyboard input..missing?
This is the correct behavior.
The keyboard lib isnt window input it's DirectInput. So your a little more low level than window messages.
If you want to repeat keys on holding down use KeyboardPushed and timing instead of Inkey.
The keyboard lib isnt window input it's DirectInput. So your a little more low level than window messages.
If you want to repeat keys on holding down use KeyboardPushed and timing instead of Inkey.
Re: streaming keyboard input..missing?
The docs for KeyboardInkey() say that it "returns the last typed character",
which is exactly what it does. It doesn't return the last key held down.
which is exactly what it does. It doesn't return the last key held down.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
"PureBasic won't be object oriented, period" - Fred.
- ultralazor
- Enthusiast

- Posts: 186
- Joined: Sun Jun 27, 2010 9:00 am
Re: streaming keyboard input..missing?
@Thorium:Which requires manually writing a entire input system for projects handling literally every single key and timing.
@PB:Yeah but there isn't an alternative unless you want to do like Thorium suggest and handle everything
@PB:Yeah but there isn't an alternative unless you want to do like Thorium suggest and handle everything
so many ideas so little time..
Re: streaming keyboard input..missing?
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.
- ultralazor
- Enthusiast

- Posts: 186
- Joined: Sun Jun 27, 2010 9:00 am
Re: streaming keyboard input..missing?
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.
Yeah, I think I seen some implementations in some game code. If I'm going to do it that way I'd probably be better off writing from scratch though. Most engines have this feature that can handle a input string including caps+shift+backspace functionality and hold it all in one buffer so you can work with it. One line replaces a couple hundred(at least). I think even older BASIC compilers had such a feature(QBASIC..omicron etc..)
so many ideas so little time..
Re: streaming keyboard input..missing?
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.
- ultralazor
- Enthusiast

- Posts: 186
- Joined: Sun Jun 27, 2010 9:00 am
Re: streaming keyboard input..missing?
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.
I just went with inkey for input and pushkey+delay(90) for backspace. It works. I use a seperate thread for drawing.
I just started seriously using PB for game programming last night, before only for easy tools.
so many ideas so little time..
Re: streaming keyboard input..missing?
This may not be appropriate for a game, and it is Windows only, AND it's not the cleanest code (wrote it a few years ago) but try this out:
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
