Grabbing key presses

BlitzMax Forums/BlitzMax Beginners Area/Grabbing key presses

Drekinn(Posted 2005) [#1]
Hi all,

1) I'm creating my own text input interface and I'd like to detect which keys are being pressed. Since the GetKey() command seems to no longer exist, what's the most efficient way to grab a key press?

As an example, I've basically been using:

If KeyHit(32) Then
inputTxt$ = inputText + " "
End If


...which works, but is a rather unnecessary approach I thought.

2) The keycodes for the - = and | keys are incorrectly documented. Does anyone know the correct codes please?

Any help would be appreciated.
Thanks.


JazzieB(Posted 2005) [#2]
GetChar() returns the ASCII value of any key entered, which should be what you're looking for for an input function.


Drekinn(Posted 2005) [#3]
JazzieB,

Yeah, I discovered GetChar() but it doesn't perform as expected, and instead displays erroneous characters.


Yan(Posted 2005) [#4]
The keycodes Here should be correct.

So this doesn't work for you?...
Graphics 640, 480, 0

Local line$

Repeat
	Cls
	DrawText " > " + line$, 10, 100
	Flip 
	
	Local char = WaitChar()
	
	Select True
		Case char >= 32
			line$ :+ Chr(char)
			
		Case char = 8
			line$ = line$[..line$.length - 1]
			
		Case (char = 27) Or (char = 13)
			Exit
	End Select
Forever

Notify line$

End



Drekinn(Posted 2005) [#5]
TwoEyedPete,

Thanks for the keycode list, though the backslash (\) keycode is still incorrect, ie. 226. The plus and minus keys now work nicely.

Thank you also for the code snippet. Yes, it works like a charm and is a much simpler approach than my own.
Changing the WaitChar() into GetChar() allows text to be typed without causing disturbance to the rest of my program.

Joyously,


ziggy(Posted 2005) [#6]
Here you have a 'cursor' version of the TwoEyedPete
routine.

Graphics 640, 480, 0

Local Line$

Repeat
	Cls                       
	Local OutputText:String = " > " + Line$
	DrawText OutputText, 10, 100 	
	If MilliSecs() mod 800 < 400 Then DrawRect(10+TextWidth( OutputText), 100,2,TextHeight("|"))
	Flip 
	Local char = GetChar()
	If char<>0 Then
		Print char 'Debug porpouses, check for spetial characters not being displayed in the BM window becouse of a incomplet default font.
		Select True
			Case char >= 32
				Line$ :+ Chr(char)
				
			Case char = 8
				Line$ = Line$[..Line$.length - 1]
				
			Case (char = 27) or (char = 13)
				Exit
		End Select     
	EndIf
	FlushMem
Forever

Notify Line$

End




Perturbatio(Posted 2005) [#7]
I did this in my code here: http://www.blitzbasic.com/Community/posts.php?topic=52060

feel free to use it yourself :)