Discerning ENTER key from NUM ENTER key

Hello everyone,

It seems that when I press either the ENTER (or RETURN) key on the main keyboard, or the one on the numeric keypad, both Keyboard.AsyncKeyDown(&H24) and Keyboard.AsyncKeyDown(&H4C) return TRUE. (Tested on Windows)

The docs say that &H24 is the RETURN key while &H4C is the NUMERIC ENTER key.

How can I correctly tell which key is actually being pressed?

For what it’s worth, I have tested it on Mac and it works as documented. Only on Windows do both keycodes return TRUE when either key is pressed.

So how can I tell which is being pressed?

True, on a Mac these keys are different. The on on the numeric keypad is Enter (which is some kind of Accept), and the other one is Return (Which adds a New Line). On Windows this distinction does not exist.

On Windows to tell which is which, you would need to get the Key Code for the key that was pressed.

Where? Keydown?

Dim KeyCode As Integer = Key.Asc

One is 13 and the other 3

1 Like

I’m trying to catch it using AsyncKeyDown. I need to be able to catch it when there may not be a window displayed.

Interesting, thanks for that info. The Xojo docs make no mention of this.

I’m trying to write hotkeys that work while the application may be running in the background. How would I get the Key Code without the KeyDown event?

Calling a Cat using Cat is better.

The Return Key is the regular key you can find in all keyboards, while the Enter Key is only on Extended Keyboards.

You may notice, if you search, that the layout draw on the key is different.

Usually, fn-Return = Enter.

Return is ASCII 13
Enter is ASCII 3

More information (as usual) can be found here:

You may be happy to get what you see at this document’ bottom.

At last, you will find the documentation about the Xojo Keyboard Object here:
https://documentation.xojo.com/api/hardware/keyboard.html#keyboard

Thanks @Emile_Schwarz, the problem I’m having is that on Windows, the keycode for Return and Enter are both returning true when either one is depressed if I poll either of them using Keyboard.AsyncKeyDown and I need to know which one is actually being pressed.

I’m unsure of how to poll key state by ascii code.

Since polling the state finds both keys to be true, I wouldn’t trust a polling method to return an accurate key.

You’ll have to narrow down where you actually need to know this information and use a KeyDown event handler to capture the keycode actually being pressed.

Because I like to spend my time on things besides what I’m supposed to be doing, I have just tested and confirmed that in KeyDown you get different key codes on Windows.

Well, the bad news is that xojo is not doing a good job with the AsyncKeyDown method.

You cant do what you want with out of the box Xojo, you can use declares. Check the KeyboardHook of the Windows Functionality Suite

Thanks for the reply. The application I’m writing allows users to select their own system-wide shortcut keys to perform certain actions while they’re in a full-screen game.

Is there any way to capture these keystrokes with KeyDown while the Xojo app doesn’t have focus?

I ended up writing my own Declares using the win32 api. GetAsyncKeyState has the same issue as Xojo and I suspect it’s what they’re using under the hood. Sadly the Windows API is just as broken in terms of telling these two keys apart, and apparently has been so for decades.

Yet there are undoubtedly approaches that are able to tell the difference, I just can’t figure out how.

Higher level apis will give you the VIRTUAL key codes, and since there are no VKC for the numeric intro, both keys are translated to the same VKC.

That is why you need the low level hook, there you have access to the flags and extended info about the key events.

1 Like