’以下代码,可以让你的程序在没有激活地状态下,按下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
[本日志由 tiancao1001 于 2021-01-21 06:01 PM 编辑]
暂时没有评论