-.- ^^ oben auf projekt / neues element hinzufügen / dann klasse
dann löscht du alles bei der klasse und gibts folgendes ein:
dann löscht du alles bei der klasse und gibts folgendes ein:
PHP Code:
Public Class clsHotKey
Implements IMessageFilter
Private Declare Function RegisterHotKey Lib "user32" (ByVal Hwnd As IntPtr, ByVal ID As Integer, ByVal Modifiers As Integer, ByVal Key As Integer) As Integer
Private Declare Function UnregisterHotKey Lib "user32" (ByVal Hwnd As IntPtr, ByVal ID As Integer) As Integer
Private Declare Function GlobalAddAtom Lib "kernel32" Alias "GlobalAddAtomA" (ByVal IDString As String) As Short
Private Declare Function GlobalDeleteAtom Lib "kernel32" (ByVal Atom As Short) As Short
Public Class HotKeyObject
Private mHotKey As Keys
Private mModifier As MODKEY
Private mHotKeyID As String
Private mAtomID As Short
Public Property HotKey() As Keys
Get
Return mHotKey
End Get
Set(ByVal value As Keys)
mHotKey = value
End Set
End Property
Public Property Modifier() As MODKEY
Get
Return mModifier
End Get
Set(ByVal value As MODKEY)
mModifier = value
End Set
End Property
Public Property HotKeyID() As String
Get
Return mHotKeyID
End Get
Set(ByVal value As String)
mHotKeyID = value
End Set
End Property
Public Property AtomID() As Short
Get
Return mAtomID
End Get
Set(ByVal value As Short)
mAtomID = value
End Set
End Property
Sub New(ByVal NewHotKey As Keys, ByVal NewModifier As MODKEY, ByVal NewHotKeyID As String)
mHotKey = NewHotKey
mModifier = NewModifier
mHotKeyID = NewHotKeyID
End Sub
End Class
Private mForm As Form
Private Const WM_HOTKEY As Integer = &H312
Private mHotKeyList As New System.Collections.Generic.Dictionary(Of Short, HotKeyObject)
Private mHotKeyIDList As New System.Collections.Generic.Dictionary(Of String, Short)
Public Event HotKeyPressed(ByVal HotKeyID As String)
Public Enum MODKEY As Integer
MOD_ALT = 1
MOD_CONTROL = 2
MOD_SHIFT = 4
MOD_WIN = 8
End Enum
Sub New(ByVal OwnerForm As Form)
mForm = OwnerForm
Application.AddMessageFilter(Me)
End Sub
Public Sub AddHotKey(ByVal KeyCode As Keys, ByVal Modifiers As MODKEY, ByVal HotKeyID As String)
If mHotKeyIDList.ContainsKey(HotKeyID) = True Then Exit Sub
Dim ID As Short = GlobalAddAtom(HotKeyID)
mHotKeyIDList.Add(HotKeyID, ID)
mHotKeyList.Add(ID, New HotKeyObject(KeyCode, Modifiers, HotKeyID))
RegisterHotKey(mForm.Handle, ID, mHotKeyList(ID).Modifier, mHotKeyList(ID).HotKey)
End Sub
Public Sub RemoveHotKey(ByVal HotKeyID As String)
If mHotKeyIDList.ContainsKey(HotKeyID) = False Then Exit Sub
Dim ID As Short = mHotKeyIDList(HotKeyID)
mHotKeyIDList.Remove(HotKeyID)
mHotKeyList.Remove(ID)
UnregisterHotKey(mForm.Handle, CInt(ID))
GlobalDeleteAtom(ID)
End Sub
Private Function PreFilterMessage(ByRef m As System.Windows.Forms.Message) As Boolean Implements System.Windows.Forms.IMessageFilter.PreFilterMessage
If m.Msg = WM_HOTKEY Then
RaiseEvent HotKeyPressed(mHotKeyList(CShort(m.WParam)).HotKeyID)
End If
End Function
End Class