Can I trust Keycodes ?

BlitzMax Forums/BlitzMax Beginners Area/Can I trust Keycodes ?

xMicky(Posted 2006) [#1]
Trying to evaluate pressing of "+" and "-" on the normal keyboard (not numpad) I find that the returned chars codes are 43 and 45. These charcodes are assigned to the Constants KEY_EXECUTE and KEY_INSERT, which have definitely nothing to do with "+" and "-". In another post of the forum I found, that there "-" was assigned to the charcode -189.
Now I wonder whether this is related somehow to national variations of key chars (I use an keyboard for german language) and therefore my programm would get different messages, if "+" and "-" are pressed on an english, french or spanish keyboard ? Aren't the chars normed internationally and if so why doesn't BlitzMax seems to care about that ?


Beaker(Posted 2006) [#2]
You can rely on the codes (and the Constants), what you can't rely on is the character/name associated with it, altho most are pretty reliable.


TomToad(Posted 2006) [#3]
43 and 45 are the ASCII codes for + and -. The constants returns scan codes. Not the same thing. In order to get the scan codes, use the constants KEY_MINUS and KEY_EQUALS. If you need to know if the + is being typed (Shift =) instead of just the key itself, you need to check for the modifier
If KeyHit(MODIFIER_SHIFT) And KeyHit(KEY_EQUALS) Then ...

You can also use GetChar which returns the next ASCII code in the queue.
Local CharacterTyped:Int

CharacterTyped = GetChar()
If CharacterTyped = 43 then ...

I don't believe that there are Constants for ASCII characters, so you need to type the code itself, or alternatively use ASC()
If CharacterTyped = Asc("+") ...



xlsior(Posted 2006) [#4]
Except... Won't doing so mess up on the different country-specific keyboards?
Not sure about the +, but on many keyboards shift 1 through 9 do not contain the 'standard' !@#$%^&*() sequence...


Tom Darby(Posted 2006) [#5]
I haven't tested it in BMax (only have QWERTY,) but I know that AZERTY keyboards are "funky" in this regard--specifically, you need to hold shift to get yer numbers (and the symbols are not in QWERTY order)...