How to GetKeyCode?

read the doc/open the firsts chapters of a book on programming.

hint: $20 = 32 = space

Keycaps are what is drawn on the keyboard while key code are the physical address of the key(s) on a keyboard

Why? If you know the keycode, you can use it in Xojo, not enough?

Wrong understanding.

What you seems to want is the currentr keyboard layout. You get it in KeyDown / KeyUp Events.

That said, Keycodes exists and as an example, in games people uses I-J-K-M (in a qwerty -US- layout); in a french keyboard that is I-J-K-?. These are what is in the key caps.
To be sure to get what you want in a game, people use key codes: the physical address of these keys.

READ THE DOCS, THERE IS A LIST OF THE CHARACTERS-KEYCODES…

as i’m an old programmer, since 1986, started programing BASIC on HP-85, i think i know at least 4 asci codes on a keyboard… tab, return, enter, space! lol

with this 4 ASCI codes, i can do a lot of cool stuffs… like read and write text files. isn’t cool?

on this example you gave me, $20 = 32 = space, it’s the ASCI code. excellent. i know it very well.

i need to get the KEY CODE (physical address)

i’m not sure, but i guess the ASCI code is not the same of KEY CODE. i think.

by the way, please, as i’m not fluent in english, please understand sometimes i can appear rude, but i’m not!

the ASCI code, i can use “only” on KEY DOWN events
the KEY CODE, i’ll use “anywhere” with Keyboard.AsyncKeyDown()

the question is simple: is there a way on xojo to get the KEYCODE when i press a key or not?

How old is your photo ? :wink:

Can you really explain what you want to do that Keyboard cannot do ?

Isn’t that what you are searching for ?

If I remember correctly, in 1986, BASIC does not have Events nor Timers…

It looks like all possibilities need to be tested with each keystroke to get the information. At least there are not that many keys.

Var lastKeyIndex As Integer = 200 ' just a guess as to the number of keys on the keyboard
Var i As Integer
Var build As String

For i = 0 To lastKeyIndex
  If Keyboard.AsyncKeyDown(i) Then 
    build = build+" "+Keyboard.KeyName(i)
  end if
next

MessageBox(build) 

You could scan through a reasonable set of values using

Keyboard.keyname(Value)

Then record the numbers where the key-name matches what you want. Should handle all cases known and unknown with keyboard input.

So like 1 through 300 or something?

After a closer look at Keyboard — Xojo documentation
it looks like &h7F or 127 is the max number of numbers to test. Returning the names was just for demonstration purposes. Returning the numbers would be more useful. Also, it looks like the keys are returned in a consistent order too, character-command-shift-option-control.

The key names would be used to map the keycodes, we know the key names not the keycodes. If you knew the keycode differences of every keyboard in the world then the question would be moot wouldn’t it?

Good point. I missed the “The following tables give the keycodes for the US Keyboard”.

Also, in the Notes it says “The async version of each Keyboard property tells you the immediate state of the key. If you want to know the state of the key when an event was queued, you should use the non-async version of the properties. These properties are updated constantly during code execution.”

Does that mean the non-async version delivers this info without needing the loop? Not sure how the “non-async version” is used.

@Alexandre_Cunha :frowning: isn’t what you are searching ?
I took it from the documentation (as I told you to read):

Also:

You know how to translate Hex values to Integer…

lol
no, no events at all… but a lot of goto…

no, the AsyncKeyDown, i need to pass the keycode then i receive a true or false

but whats the keycode for example of “x”. if i don’t know, i need to read some doc to figure out.

i want to press the key, and get the keycode.

do not work, because no Keyboard.AsyncKeyDown was pressed…

right?

and what about arrow key? and esc and option? what’s the name of them?

hum… i’m not sure…

i’m not sure if, for example the “a” key is keycode &h00
i don’t know if on other keyboard layouts it’s &h80…

all keyboards have the same keycode names? on mac, windows, linux? also not sure…

yes, but i do not know what keycode was passed.

i want to get the keycode. something like this:

var myKeyCode as integer = Keyboard.PressedKeyCode

look… 16 years ago…
https://tracker.xojo.com/xojoinc/xojo/-/issues/4502

please, thumbs up on both
https://tracker.xojo.com/xojoinc/xojo/-/issues/79697

thanks!

Screenshot 2025-08-10 131259
Not a popular request?