vb.net 全局热键 80
vb.net怎样使用全局热键?例如在我的程序窗体form1未获得焦点时,按下F4,我的程序窗体获得焦点。...
vb.net 怎样使用全局热键?例如在我的程序窗体form1未获得焦点时,按下F4,我的程序窗体获得焦点。
展开
1个回答
展开全部
见下面的代码
Public Class Form1
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, 0, Keys.F4)
'第3个参数意义: 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)
End Sub
Protected Overrides Sub WndProc(ByRef m As Message)
If m.Msg = 786 Then
Me.Activate()
End If
MyBase.WndProc(m)
End Sub
End Class
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询