getting input

BlitzMax Forums/BlitzMax Beginners Area/getting input

Graphics 800,600,0,30

While Not KeyHit(KEY_ESCAPE) 
	Cls
	
	For x = 1 To 255
	If KeyHit(x) 
	display_string$=display_string$+ Chr(x)
	EndIf
	Next
	
	time=MilliSecs()
	curtime=time
If curTime > checkTime Then
	 checkTime = curTime + 1000
	curFPS= fpscounter
 fpscounter = 0
Else
	fpscounter = fpscounter + 1
End If

DrawText "FPS: "+curfps,10,10
	 DrawText display_string,10,20
	Flip False
	
Wend


I made this input program but it only prints capitals,
does anyone know why?

Because KeyHit() uses key codes, which are not the same as ASCII codes.

KeyHit() doesn't care if you're trying for an upper case A, or a lower case A. To KeyHit(), its just A.

ah ok, how would i get input that distinguishes between upper and lower case letters

I think you can do it with GetChar but you might need to specifically poll the SHIFT keys and/or CAPS LOCK keys too.

Check the documentation for BRL.PolledInput - everything you need is in there.

:)

a quick and dirty way that i do it is as follows

Function GetFileName() 
	FlushKeys
	Local done = 0
	Local c
	Repeat
		Cls		
		DrawText "Input File Name:> " + filename:String + ".LVL", 200, 100
		c = GetChar() 
		If c <> 0
			If c = 8
				If Len(filename:String) > 0 Then filename:String = Left:String(filename:String, Len(filename:String) - 1) 
			EndIf
			Select c
				Case 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 65, 66, 67, 68, 69, 70, 71, 72,  ..
					73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90,  ..
					97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109,  ..
					110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122
						filename = filename + Chr(c) 
			End Select
		EndIf
		
		If KeyHit(KEY_ENTER) 
			FlushKeys
			done = 1
		End If
		Flip
	Until done = 1
End Function


the case numbers are the value of all the keys that i want to know have been pressed or not, in this exampel keys 1-0 ,a-z and A-Z. its not pretty and i'm sure it can be done better, but i hope that helps somewhat

'------------------------------------------------
SuperStrict
'------------------------------------------------
Graphics 640,480,0,60
Global x:Int = 0
Global ds:String = "TestString"
'------------------------------------------------
Repeat
'------------------------------------------------
	Cls
	x = GetChar()
	If x > 8
		ds=ds + Chr(x)
		Else 
		If x = 8
			ds = Left(ds, Len(ds)-1)
		EndIf
	EndIf

	DrawText ds,0,0
	DrawText x,0,16
	DrawText Len(ds),0,32

	Flip
'------------------------------------------------
Until KeyHit(key_escape)
EndGraphics
End


I've spent a little time working on this - Needs a bit of work to make it a proper INPUT-like command, but that's elementary stuff fortunately :)

oh yeah getchar works thanks everyone