EVENT_KEYDOWN hadler got only uppercase char

BlitzMax Forums/BlitzMax Beginners Area/EVENT_KEYDOWN hadler got only uppercase char

johnnyfreak(Posted 2010) [#1]
if i do this
Graphics 800, 600

While Not AppTerminate()
PollEvent
If(CurrentEvent.id = EVENT_KEYDOWN)
	Print "Key Pressed: " + CurrentEvent.data + "->" + Chr(CurrentEvent.data)
EndIf

Wend

End


I can know when a key is pressed. but i can only get, for instance, "A" not "a".
How can i get both?

Sorry for my poor english :(


Zeke(Posted 2010) [#2]
CurrentEvent.mods returns "modifier" and that tell if shift/control etc. is down.
but using EVENT_KEYCHAR returns correct ascii value.

or use this example:
Graphics 800, 600

While Not AppTerminate()
PollEvent()
	If(CurrentEvent.id = EVENT_KEYDOWN)
		Local e:TEvent = PeekEvent()
		If e.id = EVENT_KEYCHAR
			Print "Key Pressed: " + e.data + "->" + Chr(e.data)
		Else
			Print "NON KEYCHAR Key Pressed: " + CurrentEvent.data + "->" + Chr(CurrentEvent.data)
		EndIf
	EndIf
Wend

End



GfK(Posted 2010) [#3]
Don't confuse keycodes with ASCII codes.

Keycodes refer to a key on your keyboard.

ASCII codes refer to an ASCII character.

Depending on what you're doing then you may find GetChar() more useful.


xlsior(Posted 2010) [#4]
Keycodes refer to a key on your keyboard

ASCII codes to refer to an ASCII character.


...Which is a very significant difference for users on non-American keyboard layouts, where the keycode may not match up with your expected value.

for example, US = QWERTY, French = AZERTY, German = QWERTZ


johnnyfreak(Posted 2010) [#5]
Thanks a lot zeke, Gfk and Xlsior.

i need to know which key has been pressed but handling an event not using getchar or similar.
So, which one must i choose among KEYCHAR and KEYDOWN?


GfK(Posted 2010) [#6]
If you don't want to use GetChar(), then your other choices are KeyHit() and KeyDown(). Which to use depends on what you want to do.

KeyHit() will detect a single key press, while KeyDown() will always report True while a key is held down. You can determine use of SHIFT keys by using KeyDown(KEY_LSHIFT) or KeyDown(KEY_RSHIFT).

You would also have to check for use of CAPS LOCK, which is a chore in itself.


johnnyfreak(Posted 2010) [#7]
EVENT_KEYCHAR semme to work as i want.
Keyhit, down, getchar are useful function but not in this case: i want to handle events ;)