Page 1 of 1

streaming keyboard input..missing?

Posted: Wed Jul 28, 2010 7:50 am
by ultralazor
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?

Re: streaming keyboard input..missing?

Posted: Wed Jul 28, 2010 7:54 am
by PB
What do you mean? Of course a window receives keyboard input. More info, please.

Re: streaming keyboard input..missing?

Posted: Wed Jul 28, 2010 8:01 am
by ultralazor
PB wrote:What do you mean? Of course a window receives keyboard input. More info, please.
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.

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

Re: streaming keyboard input..missing?

Posted: Wed Jul 28, 2010 9:06 am
by J. Baker
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)
  EndIf

Re: streaming keyboard input..missing?

Posted: Wed Jul 28, 2010 9:24 am
by Thorium
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.

Re: streaming keyboard input..missing?

Posted: Wed Jul 28, 2010 10:55 am
by PB
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. ;)

Re: streaming keyboard input..missing?

Posted: Wed Jul 28, 2010 7:58 pm
by ultralazor
@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

Re: streaming keyboard input..missing?

Posted: Wed Jul 28, 2010 8:16 pm
by Thorium
ultralazor wrote:@Thorium:Which requires manually writing a entire input system for projects handling literally every single key and timing.
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.

Re: streaming keyboard input..missing?

Posted: Wed Jul 28, 2010 8:22 pm
by ultralazor
Thorium wrote:
ultralazor wrote:@Thorium:Which requires manually writing a entire input system for projects handling literally every single key and timing.
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.

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..)

Re: streaming keyboard input..missing?

Posted: Wed Jul 28, 2010 9:55 pm
by Thorium
ultralazor wrote: I think even older BASIC compilers had such a feature(QBASIC..omicron etc..)
QBASIC had support for DirectInput? I dont think so. Is just had the Input command thats the same in PureBasic on the console.

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.

Re: streaming keyboard input..missing?

Posted: Thu Jul 29, 2010 12:41 am
by ultralazor
Thorium wrote:
ultralazor wrote: I think even older BASIC compilers had such a feature(QBASIC..omicron etc..)
QBASIC had support for DirectInput? I dont think so. Is just had the Input command thats the same in PureBasic on the console.

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

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.

Re: streaming keyboard input..missing?

Posted: Fri Jul 30, 2010 3:14 am
by kenmo
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