When is a TAB key hex 30?

Working on keyboard navigation, referencing the documentation the TAB key is hex 30, but this code did not work for me.


If Keyboard.AsyncKeyDown(&h30) Then
// --do stuff here
Return True
End If

While working on some other keyboard navigation a lightbulb flickered on and I remembered that TAB is Hex 09.

So I tried

If Keyboard.AsyncKeyDown(&h09) Then
// – do stuff here
Return True
End If

and it worked.

So my question is, when is a TAB key Hex 30?


Seems I had fat fingered (read copy/paste) several locations were set to Hex 33 except for one of which was set correctly to Hex 30.

Strange. as I’m getting the opposite (as I would have expected). On my side, the tab key respond to key code 48.
Where are you trying your code? Which OS?

Don’t confuse the Tab character and the Tab key. The tab character (the character produced by the Tab key) is ascii 9. The tab key (physically on the keyboard) is the key 48.
Each physical key on the keyboard reports a value to the OS (e.g. 48 for tab, 1 for “s”) and the OS then maps this key to a character, given the user’s chosen layout (9 for tab, 115 for s, etc.). That’s how a specific key can produce e.g. “a” on most keyboard layouts but “q” on the french layout.

Keyboard.AsyncKeyDown checks for the physical value (for tab, 48).

Again: where does this form work for you? It’s illogical, unexpected and doesn’t behave that way on my side.

Was working in Mac.
I had one subroutine out of several keydown areas that was set correctly in Mac. Ignoring that subroutine, I added a the Hex(09) test and ran the software.

It worked but it was reading the Hex(30) routine not the Hex(09) so I incorrectly assumed the Hex(09) fixed it. My other entries all had Hex(33) which of course were incorrect.

It’s all working as expected now. Sorry for the confusion.

Please, use the correct sentences instead of…

Hex(30) is KeyCode 48
Hex(09) is Ctrl-9

Xojo do not returns Hex values in the Key Events…

As usual, wikipedia is your friend to learn the real names…

Keep in mind that different keyboards can return different key codes. Key codes correspond to the physical keys, not the ascii code that would be used to print the character. That’s why there are key codes for things like the function keys, Home, Del, Arrows and Page Up/Down.

Thanks Emile. I believe you are correct. An old dog like me thinks in terms of ascii codes and hex codes, hence the terms. I’ll need to study up more on the names XOJO uses for the scancodes / rom codes / page codes etc. That would probably have cleared it up for me and could have avoided the post. :slight_smile:

I’ll need to look into more more to get it clear in my head. Thanks for the input Greg, appreciated it. :slight_smile:

Is there any reason why you cannot use Keydown ?

Thank you Michel!

At some point in time I believe I had tried
(In the keydown event) MessageBox(key) returned a blank message for non-printable keys but would return the actual key for printable characters. For whatever reason, I would have expected a string or character sequence being returned. I quickly dismissed it and went looking for something else.
At that time, I had switched to the AsyncKeyDown and never looked back.

But yes after looking again, this indeed this also would work.
I appreciate the feedback :slight_smile:

1 Like

I’m re-reading this again and am putting this paragraph into my personal notes. Thanks for this explanation Arnaud.

1 Like