Detect Keystrokes

It is possible to catch any keystrokes that are made while a Form is displayed by implementing the IMessageFilter interface.
The following code will catch the Excape key on a key down.


Public Class frmMain 
   Inherits System.Windows.Forms.Form

   Implements IMessageFilter

   Private Function PreFilterMessage(ByRef m As Message) As Boolean Implements IMessageFilter.PreFilterMessage
      
   End Function

   Private Sub frmMain_Load(ByVal sender As System.Object, _
                            ByVal e As System.EventArgs) _
                            Handles MyBase.Load

      Application.AddMessageFilter(Me)
   End Sub

End Class


© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext