difference between an ASCII value and ASCII code

Blitz3D Forums/Blitz3D Beginners Area/difference between an ASCII value and ASCII code

killerhedgehog(Posted 2009) [#1]
I have been trying to use getkey and waitkey to help me find ASCII codes for various keys needed in my games but the value returned seems to have no correlation to the key pressed. Is there a reason for this?


Ross C(Posted 2009) [#2]
I think your best bet is to check for scancodes and convert them into ASCII, as getkey does not return special function keys.

From the docs:


This command will check to see if a key has been pressed and will return its ASCII value. Not all keys have ASCII values - if you need to trap SHIFT, ALT, or other non-ASCII compliant key, try KeyHit or KeyDown.




Abomination(Posted 2009) [#3]
Getkey() returns the ascii and waitkey() returns the scancode.
The scancode can differ for other keyboards, but Getkey should return the same vallue as used by windows.
I just spend 2 days trying to make my input-routine working the same for 3 different keyboards I have.
I You want some specifics. I can Give you some.


Warner(Posted 2009) [#4]
I believe they are both returing the Ascii value. If you want to use the scancode (as used by keydown/keyhit), try this routine instead:
.start
test = -1
For i = 0 To 255
 If KeyDown(i) Then test = i
Next
If (test <> -1) And (test <> old) Then Print test: old = test
Goto start



Abomination(Posted 2009) [#5]
Is there egg on my face?
I meant to type keyhit. Not WaitKey.
Dyslexia rears its ugly head!

Anywho... The snippit from Warner will give different results on an american,U.K. or German Keyboard.
But print chr$(WaitKey()) should print the correct letter of the corresponding key-press.


Ross C(Posted 2009) [#6]
*Ross scraps the egg off and puts it in a sandwich.


Abomination(Posted 2009) [#7]
Bon appétit, monsieur!


Ross C(Posted 2009) [#8]
lol


b32(Posted 2009) [#9]
I was surprised to find out that Waitkey() returns a number; which is nice to know. But do I understand correcly, that on a German keyboard layout (that's AZERTY, right ?) the scancode for -for instance- "Q" is not 16 ?


Abomination(Posted 2009) [#10]
not sure about that one.
But on my UK keyboard there's a "£" where a "#" could be.
So scancode for "£" is 4.
scancode for "#" is 43, witch "should" be "\", witch on this keyboard
is 86 (OEM_102)
/edit
And this all under the assumption that the keyboard in question is configured correctly!
/end edit


jfk EO-11110(Posted 2009) [#11]
Use Getkey for Alphanumeric Input to get the right Chars. If Getkey gives nothing, you still have to do a

pressed=0
for i=1 to 255
if keyhit(i) then
pressed=i
exit
endif
next

And then do whatever you need to do with "pressed", eg. check if
the user hit Shift or an other key you can't test with getkey().

Working directly with KeyDown(n) is only useful when you need mutliple keys to be pressed simultanously, eg. to run forward and strafe or crouch at the same time. This is limited to 3 keys as far as I know.


_PJ_(Posted 2009) [#12]
Heh I neever knew Waitkey returned a value at all. Very handy that.

What suprises me most, though, is that presumbly, the scancodes are DirectInput related... surely DirectX is regionally configured?