日照市东港区创新电子技术中心
ndfweb.cn

vb.net里最简单的全局热键代码


2023-03-31 13:12:46 (2049)


 

 

’以下代码,可以让你的程序在没有激活地状态下,按下F4让你的程序处理活动状态,并可添加你想要的功能。

’vb.net 2012调试通过

 

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


了解更多请访问:http://www.ndfweb.cn/news-926.html
  NDF俱乐部
  国际域名注册
  建站咨询
合作伙伴:万网 | 新网 | 新网互联 NDF网站建设淘宝店 | 实用工具 | 外貿網站建設 | 联系我们
鲁公网安备 37110202000336号 Sitemap - RSSRSS订阅