如何编写隐藏程序使用的热键

时间:2016-07-20 03:49:27

标签: .net vb.net keypress hotkeys registerhotkey

我再次请求帮助!

我希望能够注册从隐藏表单运行的多个热键。下面的示例程序的热键在按下ALT + UPKEY时切换第二个表单。现在它按预期执行,但是当我取消注释隐藏程序的代码时,热键不再起作用。任何人都知道我在哪里出错,或者可能知道如何从隐藏程序切换第二个表单?一如既往,感谢您的帮助。

Public Class Form1

Public Declare Function RegisterHotKey Lib "user32" (ByVal hwnd As IntPtr, ByVal id As Integer, ByVal fsModifiers As Integer, ByVal vk As Integer) As Integer
Public Declare Function UnregisterHotKey Lib "user32" (ByVal hwnd As IntPtr, ByVal id As Integer) As Integer
Public Const WM_HOTKEY As Integer = &H312

Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
    If m.Msg = WM_HOTKEY Then
        Form2.Show()
    End If

    MyBase.WndProc(m)

End Sub


Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
    Call UnregisterHotKey(Me.Handle, 9)

End Sub


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Call RegisterHotKey(Me.Handle.ToInt32, 0, &H1, 38) '<-- registers specific hotkeys

    'Me.KeyPreview = True
    'Me.ShowInTaskbar = False
    'Me.ShowIcon = False
    'Me.Visible = False

End Sub
End Class

0 个答案:

没有答案