Keycodes By Numbers

BlitzMax Forums/BlitzMax Programming/Keycodes By Numbers

dw817(Posted 2015) [#1]


Does someone have a list of all the raw keycodes for BlitzMAX ?

Not the variables which are hardcoded such as key_space, key_a, etc. No, I want the decimal list from 1-255 where space is 32, "a" is 65, and "/" is 191. I can't find that in BlitzMAX help.

Thanks in advance.


Zethrax(Posted 2015) [#2]
You can find a list of the decimal values in this code archive entry: http://www.blitzbasic.com/codearcs/codearcs.php?code=1340


dw817(Posted 2015) [#3]
Excellent, thank you, Zethrax ! Now I can write this:

' Small & Fast code to read and retrieve raw keystrokes
' Written by David W 12-14-15

Strict
Global i,kc,k$
Global rk$="1bes70f171f272f373f474f575f676f777f878f979f07af!7bf@300 311 322 333 344 355 366 377 388 399 bd- bb= 08bs24ho23en6fn/6an*6dn-c0` 09ta41a 42b 43c 44d 45e 46f 47g 48h 49i 4aj 4bk 4cl 4dm 4en 4fo 50p 51q 52r 53s 54t 55u 56v 57w 58x 59y 5az db[ dd] dc\ 2ede21pu24ho26up21pu6bn+ba; de' 0dcr22pd25lf0cn527rtbc, be. bf/ 23en28dn22pd2din20  "
Graphics 640,480
SetScale 5,5
Repeat
  k$=""
  For i=1 To Len(rk$)Step 4
    kc=("$"+Mid$(rk$,i,2)).toint()
    If KeyDown(kc)
      k$=Trim$(Mid$(rk$,i+2,2))
      If k$=""
        k$=" "
      EndIf
      Exit
    EndIf
  Next
  Cls
  DrawText k$,50,50
  Flip
Until k$="es"


I don't know if BlitzMAX is planning on making any upgrades in the future, but a way of reading a raw keystroke held that is automatically converted to its ASCII equivalent would make this code a lot easier and and the keycodes not appear so random.


Henri(Posted 2015) [#4]
Hi,

you could have an array of all the ascii equilavents of keycodes for faster access.
'Pseudo code
char:String = codes[keycode]

-Henri


dw817(Posted 2015) [#5]
That would work. Blitz could basically have an INKEY$ like regular basic has.
  a$=inkey$()
  if a$>""
    print a$;
  endif



TomToad(Posted 2015) [#6]
That would work. Blitz could basically have an INKEY$ like regular basic has.

Function Inkey:String()
    Return Chr(GetChar())
End Function



dw817(Posted 2015) [#7]
Wow, that does work, TomToad ! I did not know about that command, or in this case, function. It does seem to work with CTRL key codes too, such as CTRL Q to exit.

For videogames I can see you would just want to read the raw arrow keys, but for normal keystrokes, your INKEY routine would be just fine and circumvents me from having to write a keyboard routine that includes shift and control.

Still, you can't have a CTRL number, like for a hotkey interface. I may stick with my current keyboard routine, but it's nice to see for small projects there is a type of INKEY function. Thank you !

Graphics 1024,768
Local k$,i
SetScale 5,5
Repeat
  Cls
  k$=inkey$()
  For i=0 To 3
    If KeyDown(37+i)Then k$=Mid$("lfuprtdn",i*2+1,2)
  Next
  DrawText k$,50,50
  Flip
Until k$=Chr$(17)Or k$=Chr$(27)

Function Inkey:String()
    Return Chr(GetChar())
End Function