Programming the Enter key (both of them)

Programming the Enter key (both of them)

I have a window that has some ComboBoxes and a ListBox.
I’ve written code in a Timer to recognize when the user presses a key combination. Control+C would cause the focus to go to a specific ComboBox.

I’m using the code ;

If Keyboard.AsyncControlKey Then
If Keyboard.AsyncKeyDown(&h08) Then // Ctrl-C
cmbCommunity.SetFocus
End If
End If

On the ListBox’s KeyDown event I have the code ;

if key=chr(13) then
OfficesList.Close
Search_PROGRAMS.Close

end if

This works fine; however, does not take into account the Enter key on the numeric keypad. In order to do that, I have to include chr(3) as follows;

if key=chr(13) or key=chr(3) then
OfficesList.Close
Search_PROGRAMS.Close

end if

In addition, I also use similar code to force the cursor from one ComboBox to another.

The problem becomes, if I include the “or key=chr(3)”, when a user presses Control+C, that produces a chr(3) code as well and therefore will close the window if the focus is on the ListBox (runs the Key/down event code of the ListBox.

I could use a different letter such as “m” but to remain consistent with other aspects of the program and to avoid a lot of re-programming, Ctrl+C is the preferred choice.

I did try using the following in the Timer;

If Keyboard.AsyncKeyDown(&h4C) Then  // Enter
  OfficesList.Close
  Search_PROGRAMS.Close
  
End If

The problem with this is it circumvents the KeyDown event of the ComboBoxes so instead of moving the focus from one ComboBox to another, it closes the window.

Anyone have suggestions on how I can accomplish trapping the numeric Enter key a different way?