09-22-2009, 09:46 PM
I am trying button keydown event. Why when I hit Arrow Down, Up, Left, Right and Tab the event does not fire.
Private Sub cmdTest(KeyCode As Integer, Shift As Integer)
Debug.Print "KeyCode: " & KeyDown
I already put toggle breakpoint to know if the event raise but it does not stop.
I use vb6.0 and Windows XP
Jerome and Gail
09-23-2009, 05:32 AM
Firstly, that subroutine that you posted will not handle a keydown event...
it should be named Form_KeyDown(Keycode as Integer, Shift as Integer) or likewise for a different control
Secondly, the keydown event will not fire if:
KeyPreview is set to False and you have lightweight controls on your form
if you have a heavy control such as a command button or listbox on your form.
09-23-2009, 05:42 AM
The Tab and Arrow keys (and a few others) are trapped by the window processing logic to support moving the control focus around among the various controls on the form or for special cursor handling within a control like the TextBox.
It is possible to set the KeyPreview property of the Form to True and then a KeyDown() event routine at the form level will see the Arrow Keys. You can put logic to see which control has focus and devise a custom filter as to where arrow keys will apply. There are still a few keys that the Form will not see though and Tab is one of them.
What this means is that it is best to design your application around the conventional Windows key usage and not take that behavior away from the user.