Capturing the “enter key press”

Hi folks,
I am trying to capture or receive the “Enter” key being press while my app is active (both mac os and windows versions). I have read a few of the snippets in the forum, but I am still not clear on this. Here is the code I have tried inside the main Event Handler Key Down event for my app. When I step through this in the debugger, when the enter key is press, the Key As String Variable is set 0D, but it skips my code. What am I missing?

If Keyboard.AsyncKeyDown(&h0D) then
     SendGo //send the remote command
End

Miss-read the post

If all you want is to know that the “Enter” key was pressed, in the KeyDown Event just do…

if Key = Chr(3) Then //do something End If

Roger,
I had to use Chr(13) instead of Chr(3). I have not tested it on Windows yet just getting the mac version going now.

If Key = Chr(13) thrn
  SendGo // call my methond
  Return True
End

I tried the samething to capture the spacebar Chr(32), but no luck on that.

You should check for both, Chr(3) is the numeric keypad enter key, Chr(13) is the main enter key.

What is it you’re doing with these keys after capturing them? We may have a better suggestion.

What control is your KeyDown even on?

Hi Roger,
What I am trying to do is pretty simple actually. My app will remote controlling multiple video players at the same time. I need three standard keyboard shortcuts. By standard, I mean what everyone who uses these players expects certain shortcuts to do. One, the enter key will start a selected video playing, two, the spacebar does a pause/continue playing toggle and three, the esc key will stop the video that is playing. I have the rest of the app running fine and on screen buttons run my methods exactly as expected, it is just getting these shortcuts working. Currently, I now have the enter working thsnks to Roger.

Julian,
Currently, I have they Keydown event in the event handler for the main screen/window for the app.

I was able to get the ESC key to wotk iding a CANCEL button.

SELECT CASE ASCB(key)
CASE 8 // backspace key
.. do something
RETURN TRUE
CASE 27 // Escape key
.. do something
RETURN TRUE
CASE 127 // delete key
.. do something
RETURN TRUE
CASE 9 // TAB key
.. do something
RETURN TRUE
CASE 13 // RETURN KEY
.. do something
RETURN TRUE
CASE 3 // ENTER KEY
.. do something
RETURN TRUE
CASE 28 // Arrow Key
.. do something
RETURN TRUE
CASE 29// Arrow Key
.. do something
RETURN TRUE
CASE 30// Arrow Key
.. do something
RETURN TRUE
CASE 31// Arrow Key
.. do something
RETURN TRUE
END SELECT

similar can be done for the rest of the keys

Chr(32) should also work for the space bar. Don’t know why that didn’t work for you.
Also, be aware that some controls can steal the focus from the window. In that case, the keydown event won’t go where you think it will.

[quote=369352:@James M Wadkins]Roger,
I had to use Chr(13) instead of Chr(3). I have not tested it on Windows yet just getting the mac version going now.

If Key = Chr(13) thrn
  SendGo // call my methond
  Return True
End

I tried the samething to capture the spacebar Chr(32), but no luck on that.[/quote]

Chr(3) is the numeric keypad return. Chr(13) is the typewrited keypad return.

That said, where did you put your code ?

If you want to detect a key press regardless of whether your app has focus or not you can use a timer and put the following code in the action event.

if Keyboard.AsyncKeyDown(&h31) then MsgBox("Space")

[quote=369475:@Roger Clary]Chr(32) should also work for the space bar. Don’t know why that didn’t work for you.
Also, be aware that some controls can steal the focus from the window. In that case, the keydown event won’t go where you think it will.[/quote]
I did end up going with a Select Case option…Doh, can’t believe that slip by my. This is the reason my Chr(32) dud not work. The KeyDown was only processing the first if statement. The Select case fixed thst.

Thank you all.