Keyboard.AsyncKeyDown not working with Enter or Return?

I’m checking for a return or enter key in a textarea, but none of the lines of the code below registers a Return or Enter key.

If Keyboard.AsyncKeyDown(&h24) Then
  System.DebugLog ("Return")
  Return True
End If

If Keyboard.AsyncKeyDown(&h4C) Then
  System.DebugLog ("Enter")
  Return True
End If

If Keyboard.AsyncKeyDown(36) Then
  System.DebugLog ("Return Dec")
  Return True
End If

If Keyboard.AsyncKeyDown(76) Then
  System.DebugLog ("Enter Dec")
  Return True
End If

How/where are you using that code?
What version of Xojo?
What version of OS?

No problems here with this code in TextField - KeyDown event:

If Keyboard.AsyncKeyDown(&h24) Then
  System.DebugLog ("Return")
  Break
End If

If Keyboard.AsyncKeyDown(&h4C) Then
  System.DebugLog ("Enter")
  Break
End If

Xojo2023r4
macOS 13.6.7 (Intel)

I’m using it in the keydown event of a DesktopTextArea, Xojo 2024 R1.1, macOS 14.5

link to sample project: Sample Test Project

No problems here with Xojo2024r1.1 and macOS 14.5, using your sample.
I see the debuglog messages.

Looks like restarting my Mac fixed this weird error.

2 Likes

Was gonna ask if you had any other controls grabbing the focus, or any buttons set as ‘default’ which might catch the enter key…

You aren’t meant to use the Async functions in the KeyDown event, you should be checking the key as String parameter from the event.

4 Likes