我自己来解决
'p 这是窗体设计器中不要修改只能加入代码
'Form 重写 Dispose,以清理组件列表。
<System.Diagnostics.DebuggerNonUserCode()> _
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
MyBase.Dispose(disposing)
End Sub
'Windows 窗体设计器所必需的
Private components As
'注意: 以下过程是 Windows 窗体设计器所必需的
'可以使用 Windows 窗体设计器修改它。
'不要使用代码编辑器修改它。
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
End Sub
'以下是你要加入的代码位置:
Public Const WM_HOTKEY = &H312
Public Const MOD_ALT = &H1
Public Const MOD_CONTROL = &H2
Public Const MOD_SHIFT = &H4
Public Const GWL_WNDPROC = (-4)
Const KEYEVENTF_EXTENDEDKEY As Short = &H1S
Const KEYEVENTF_KEYUP As Short = &H2S
Const MOUSEEVENTF_LEFTDOWN As Short = &H2S
Const MOUSEEVENTF_LEFTUP As Short = &H4S
Const MOUSEEVENTF_MIDDLEDOWN As Short = &H20S
Const MOUSEEVENTF_ABSOLUTE As Short = &H8000S
Const MOUSEEVENTF_RIGHTDOWN As Short = &H8S
Const MOUSEEVENTF_MIDDLEUP As Short = &H40S
Const MOUSEEVENTF_MOVE As Integer = &H1S
Const MOUSEEVENTF_RIGHTUP As Short = &H10S
Public Const WM_CLOSE = &H10
Friend WithEvents Button1 As System.Windows.Forms.Button
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
End Class
'这是form1
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
RegisterHotKey(Handle, 0, MOD_CONTROL Or MOD_ALT, Asc("L"))
End Sub
Protected Overrides Sub WndProc(ByRef m As Message)
If m.Msg = WM_HOTKEY Then
If Visible Then
Hide()
Else
Show()
End If
End If
MyBase.WndProc(m)
End Sub
Private Sub Form1_Closed(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Closed
UnRegisterHotKey(Handle, 0)
End Sub
End Class