I would use ProcessCmdKey for that ESC Button.. Form.KeyDown never worked well for me ;)
Protected Overrides Function ProcessCmdKey(ByRef msg As Message, keyData As Keys) As Boolean
If keyData = Keys.Escape Then
Console.WriteLine("Yeha Esc pushed..")
Return True
End If
Return MyBase.ProcessCmdKey(msg, keyData)
End Function
Back then in VB6 I used
GetAsyncKeyState
when I needed to detect Keys pressed outside my App. But unfortunately you need an extra Thread or an Timer for that, as you allways need to check if your Keys are pressed. Don't know if there are better ways now, never needed that functionality in the last years... ^^
(I guess 4 sure there are, but I don't know em)
Here is a litte example
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As IntPtr) As IntPtr
Private Sub Timer_Or_Thread_WhateverRoutine
Dim result As IntPtr = GetAsyncKeyState(New IntPtr(Keys.F5))
If result.ToInt32 < 0 Then
MessageBox.Show("F5 Pushed")
End If
End Sub