全局鍵盤鉤子 Public Declare Auto Function RegisterHotKey Lib "user32.dll" Alias _ "RegisterHotKey" (ByVal hwnd As IntPtr, ByVal id As Integer, ByVal fsModifiers As Integer, ByVal vk As Integer) As Boolean Public Declare Auto Function UnRegisterHotKey Lib "user32.dll" Alias _ "UnregisterHotKey" (ByVal hwnd As IntPtr, ByVal id As Integer) As Boolean Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load RegisterHotKey(Handle, 0, 7, Keys.C) RegisterHotKey(Handle, 1, Nothing, Keys.L) ' 0=nothing 1 -alt 2-ctrl 3-ctrl+alt 4-shift 5-alt+shift 6-ctrl+shift 7-ctrl+shift+alt End Sub Private Sub Form1_Closed(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Closed UnRegisterHotKey(Handle, 0) UnRegisterHotKey(Handle, 1) End Sub Protected Overrides Sub WndProc(ByRef m As Message) If m.Msg = 786 Then If m.WParam.ToInt32 = 1 Then MsgBox(m.Msg) ElseIf m.WParam.ToInt32 = 0 Then MsgBox(m.Msg) End If TextBox1.Text &= " " & m.Msg End If MyBase.WndProc(m) End Sub |
|