From b0da6637568e2ca638ac6daba2c4b856aea104de Mon Sep 17 00:00:00 2001 From: Jonathan Jenne Date: Wed, 3 Mar 2021 10:32:36 +0100 Subject: [PATCH] Windows: Improve Hotkey --- Windows/Hotkey.vb | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/Windows/Hotkey.vb b/Windows/Hotkey.vb index 970dba1d..d0d654ee 100644 --- a/Windows/Hotkey.vb +++ b/Windows/Hotkey.vb @@ -1,4 +1,6 @@ -Imports System.Windows.Forms +Option Explicit On + +Imports System.Windows.Forms Public Class Hotkey Implements IMessageFilter @@ -10,7 +12,7 @@ Public Class Hotkey ''' ''' Diesem Event wird immer die zugewiesene HotKeyID übergeben, wenn eine HotKey Kombination gedrückt wurde. ''' - Public Event HotKeyPressed(ByVal HotKeyID As String) + Public Event HotKeyPressed(HotKeyID As String) ''' ''' Definiert verfügbare Modfier Keys @@ -22,7 +24,7 @@ Public Class Hotkey MOD_WIN = 8 End Enum - Sub New(ByVal pOwnerForm As Form) + Sub New(pOwnerForm As Form) _OwnerForm = pOwnerForm Application.AddMessageFilter(Me) End Sub @@ -33,13 +35,12 @@ Public Class Hotkey ''' Den KeyCode für die Taste ''' Die Zusatztasten wie z.B. Strg oder Alt, diese können auch mit OR kombiniert werden ''' Die ID die der Hotkey bekommen soll um diesen zu identifizieren - Public Sub AddHotKey(ByVal pKeyCode As Keys, ByVal pModifiers As ModfierKey, ByVal pHotKeyID As Integer) + Public Sub AddHotKey(pKeyCode As Keys, pModifiers As ModfierKey, pHotKeyID As Integer) If _HotkeyIDList.ContainsKey(pHotKeyID) = True Then Exit Sub End If - Dim oHotkeyId As Short = NativeMethods.GlobalAddAtom(pHotKeyID) - _HotkeyIDList.Add(pHotKeyID, oHotkeyId) + Dim oHotkeyId As Short = NativeMethods.GlobalAddAtom(pHotKeyID.ToString()) _HotkeyList.Add(oHotkeyId, New HotKeyObject(pKeyCode, pModifiers, pHotKeyID)) NativeMethods.RegisterHotKey(_OwnerForm.Handle, oHotkeyId, _HotkeyList(oHotkeyId).Modifier, _HotkeyList(oHotkeyId).HotKey) @@ -67,15 +68,16 @@ Public Class Hotkey RaiseEvent HotKeyPressed(_HotkeyList(CShort(m.WParam)).HotKeyID) End If End If + Return False End Function Public Class HotKeyObject - Public Property HotKey() As Keys - Public Property Modifier() As ModfierKey - Public Property HotKeyID() As String - Public Property AtomID() As Short + Public Property HotKey As Keys + Public Property Modifier As ModfierKey + Public Property HotKeyID As Integer + Public Property AtomID As Short - Sub New(ByVal NewHotKey As Keys, ByVal NewModifier As ModfierKey, ByVal NewHotKeyID As String) + Sub New(NewHotKey As Keys, NewModifier As ModfierKey, NewHotKeyID As Integer) HotKey = NewHotKey Modifier = NewModifier HotKeyID = NewHotKeyID