You need to set the KeyPreview property for each True form. Subsequently, you can catch keyboard events at the form level in addition to the individual control level:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer) Debug.Print "Form_KeyDown" End Sub Private Sub Form_KeyPress(KeyAscii As Integer) Debug.Print "Form_KeyPress" End Sub Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer) Debug.Print "Form_KeyUp" End Sub
Essentially, the form gets a βpreviewβ of each keyboard event in front of the control, for example
Form_KeyDown Control_KeyDown Form_KeyUp Control_KeyUp
As for SetWindowsHook and SetWindowsHookEx, the first is the original Win16 API, and the latter is a call to Win32 and Win64 API. As far as I know, SetWindowsHook is deprecated and is not in the current MSDN library.
source share