[SOLVED] Key Code...

BlitzMax Forums/BlitzMax Programming/[SOLVED] Key Code...

vinians(Posted 2013) [#1]
Guys, Im creating an interpreter and I need to know the keycodes to make some defines, how can I get these codes ? Theres no lastkey in blitzmax.. I need to make a test program where I press any key and get key code, how can I?

SOLVED with
Graphics 320, 240
While (KeyDown(27) = 0)
	Cls
	SetColor(255, 255, 255)
	For Local i% = 1 To 255
		If (KeyDown(i))
			DrawText("CODE:" + i, 10, 10)
		End If
	Next
	Flip
Wend



Kryzon(Posted 2013) [#2]
You can also use the following. It's WaitEvent() based, so it should be really CPU friendly.
Local keyCode:Int
Local exitProgram:Byte = False

While Not exitProgram

	WaitEvent()

	Select EventID()
		
		Case EVENT_KEYDOWN

			keyCode = EventData()
			'Do whatever you want with the keyCode value.		

			If keyCode = KEY_ESCAPE Then exitProgram = True
		
		Case EVENT_APPTERMINATE
			
			exitProgram = True 

	End Select

Wend

This is also another way, using WaitChar(). Although, if you're going to make an application, you should use the above as it fits well with MaxGUI and gadget events.
Local keyCode:Int
Local exitProgram:Byte = False

While Not exitProgram

	keyCode = WaitChar()	
	
	If keyCode = KEY_ESCAPE Then
		exitProgram = True
	Else
	
		'Do something with 'keyCode' here.
	
	EndIf
Wend
All the keycode names can be found in the IDE home, by going to Module Reference -> User Input -> BRL.Keycodes.