Odd behavior in KeyDown event

In my experience, it’s the same on Windows. The keypad Enter gives chr(3).

I have an extended Apple keyboard and, I’ve checked again right now, Return gives me 13 and Enter 3.
Which keyboard type do you have? Are both keys separate?

I have to say my experiments are dating around 20 years ago and I no longer have a practical Windows computer to test on. At that time, though, I’m sure both keys were seen the same in Xojo (RealBasic/RealStudio), with chr(13).

My experience begins at RB 2005. Ever since that time, the keypad gives chr(3). Of course, that was the point that RB on Windows finally matured. Perhaps it was different in the Windows version’s infancy.

Yes, both keys separated also an extended Apple keyboard. The problem is that I was not clear on what I’m doing. I used OP’s code and asc(key) code. The latter is what always gives 13.

Here is the code in Keydown event of a DesktopSearchField:

If Keyboard.AsynckeyDown(&h24) then
  System.DebugLog("Return pressed")
end if
if Keyboard.AsyncKeyDown(&h4c) Then
  System.DebugLog("Enter pressed")
end if
if asc(key) = 13 then
  System.DebugLog("Return or Enter?")
end if

let me know if your results are different than mine or if I’m doing something wrong. Thanks.

Edit: this is what I get:

6:21:02 AM : SearchFieldKeyDownIssue Launched
6:21:04 AM : Return pressed
           : Return or Enter?
6:21:09 AM : Enter pressed
           : Return or Enter?
6:21:28 AM : SearchFieldKeyDownIssue Ended

is this normal?


Edit2: tried the same code in a DesktopTextField and I get:

6:28:00 AM : SearchFieldKeyDownIssue Launched
6:28:03 AM : Return pressed
           : Return or Enter?
6:28:05 AM : Enter pressed
6:28:30 AM : SearchFieldKeyDownIssue Ended

so it is a Xojo bug #75259.

1 Like

Can you test using a DesktopTextField control to see if you have a different result?

As you can see above I’m getting a different result with asc(key) between DesktopSearchField and DesktopTextField so I’m wondering if you may get a different result too.

During the course of my investigation I discovered that DesktopTextField actually does work as I would expect it to.

1 Like

Thank you.

In short DesktopSearchField has 2 bugs present on Windows and one of those present on Mac too.

1 Like

Agreed

Add findings, expectations and behavioral differences per OS for each case.

Right, this is actually the difference between Keyboard.AsyncKeyDown and the Key parameter of a key down event.
Keyboard.AsyncKeyDown returns the state of a physical key, so, of course, Enter and Return are different keys, thus have distinct values.

“Key” is what the OS reports in an event (the logical key’s value, not the physical one). Those have already been mapped according to the keyboard’s layout, so, for instance, for the physical key numbered 16, you’ll get Key=“Y” on an english keyboard but Key=“Z” on a german one (logical values).

Several physical keys can produce the same logical character, of course.

Why the difference between DesktopSearchField and DesktopTextField?

With DesktopTextField key for Return and Enter are different.

Edit: maybe I’m not understanding what you are trying to say. Maybe is just an explanation of different keyboards and not directly to Return/Enter.

For that, I don’t know. The reported issue makes much sense.

No, I think you understood what I was saying. I was just not talking about the DesktopSearchField, which I’ve not yet ever used, and definitively seems to be a different control than the DesktopTextField.

1 Like

I just realize:

What a strange idea to use

If Keyboard.AsynckeyDown

in a KeyDown Event…

1 Like