1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | Imports System.Runtime.InteropServices Public Class Form1 Public Const KEY_ALT As Integer = &H1 Public Const KEY_CONTROL As Integer = &H2 Public Const KEY_SHIFT As Integer = &H4 Public Const WM_HOTKEY As Integer = &H312 <DllImport("User32.dll")> _ Public Shared Function RegisterHotKey(ByVal hwnd As IntPtr, _ ByVal id As Integer, ByVal fsModifiers As Integer, _ ByVal vk As Integer) As Integer End Function <DllImport("User32.dll")> _ Public Shared Function UnregisterHotKey(ByVal hwnd As IntPtr, _ ByVal id As Integer) As Integer End Function Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load RegisterHotKey(Me.Handle, 1, KEY_ALT, Keys.N) RegisterHotKey(Me.Handle, 2, KEY_ALT, Keys.C) 'RegisterHotKey(Me.Handle, 1, 0, Keys.F8) End Sub Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message) If m.Msg = WM_HOTKEY Then Dim id As IntPtr = m.WParam Select Case (id.ToString) Case "1" Me.Show() Me.WindowState = FormWindowState.Normal Me.Activate() Me.Focus() Case "2" Me.Hide() Me.WindowState = FormWindowState.Minimized End Select End If MyBase.WndProc(m) End Sub Private Sub Form1_FormClosing(ByVal sender As System.Object, _ ByVal e As System.Windows.Forms.FormClosingEventArgs) _ Handles MyBase.FormClosing UnregisterHotKey(Me.Handle, 1) UnregisterHotKey(Me.Handle, 2) End Sub End Class |
2020年5月18日 星期一
vb.net 全域快速鍵 [Global HotKey]
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言