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?
difference between an ASCII value and ASCII code
Blitz3D Forums/Blitz3D Beginners Area/difference between an ASCII value and ASCII code 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.
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.
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.
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.
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.
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 scraps the egg off and puts it in a sandwich.
Bon appétit, monsieur!
lol
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 ?
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
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
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.
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.
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?
What suprises me most, though, is that presumbly, the scancodes are DirectInput related... surely DirectX is regionally configured?