ZooFlow: WIP Clipboard Watcher integration
This commit is contained in:
84
Windows/Hotkey.vb
Normal file
84
Windows/Hotkey.vb
Normal file
@@ -0,0 +1,84 @@
|
||||
Imports System.Windows.Forms
|
||||
|
||||
Public Class Hotkey
|
||||
Implements IMessageFilter
|
||||
|
||||
Private _OwnerForm As Form
|
||||
Private _HotkeyList As New Dictionary(Of Short, HotKeyObject)
|
||||
Private _HotkeyIDList As New Dictionary(Of String, Short)
|
||||
|
||||
''' <summary>
|
||||
''' Diesem Event wird immer die zugewiesene HotKeyID übergeben, wenn eine HotKey Kombination gedrückt wurde.
|
||||
''' </summary>
|
||||
Public Event HotKeyPressed(ByVal HotKeyID As String)
|
||||
|
||||
''' <summary>
|
||||
''' Definiert verfügbare Modfier Keys
|
||||
''' </summary>
|
||||
Public Enum ModfierKey As Integer
|
||||
MOD_ALT = 1
|
||||
MOD_CONTROL = 2
|
||||
MOD_SHIFT = 4
|
||||
MOD_WIN = 8
|
||||
End Enum
|
||||
|
||||
Sub New(ByVal pOwnerForm As Form)
|
||||
_OwnerForm = pOwnerForm
|
||||
Application.AddMessageFilter(Me)
|
||||
End Sub
|
||||
|
||||
''' <summary>
|
||||
''' Diese Funktion fügt einen Hotkey hinzu und registriert ihn auch sofort
|
||||
''' </summary>
|
||||
''' <param name="pKeyCode">Den KeyCode für die Taste</param>
|
||||
''' <param name="pModifiers">Die Zusatztasten wie z.B. Strg oder Alt, diese können auch mit OR kombiniert werden</param>
|
||||
''' <param name="pHotKeyID">Die ID die der Hotkey bekommen soll um diesen zu identifizieren</param>
|
||||
Public Sub AddHotKey(ByVal pKeyCode As Keys, ByVal pModifiers As ModfierKey, ByVal pHotKeyID As Integer)
|
||||
If _HotkeyIDList.ContainsKey(pHotKeyID) = True Then
|
||||
Exit Sub
|
||||
End If
|
||||
|
||||
Dim oHotkeyId As Short = NativeMethods.GlobalAddAtom(pHotKeyID)
|
||||
_HotkeyIDList.Add(pHotKeyID, oHotkeyId)
|
||||
_HotkeyList.Add(oHotkeyId, New HotKeyObject(pKeyCode, pModifiers, pHotKeyID))
|
||||
|
||||
NativeMethods.RegisterHotKey(_OwnerForm.Handle, oHotkeyId, _HotkeyList(oHotkeyId).Modifier, _HotkeyList(oHotkeyId).HotKey)
|
||||
End Sub
|
||||
|
||||
''' <summary>
|
||||
''' Diese Funktion entfernt einen Hotkey und deregistriert ihn auch sofort
|
||||
''' </summary>
|
||||
''' <param name="pHotKeyID">Gibt die HotkeyID an welche entfernt werden soll</param>
|
||||
Public Sub RemoveHotKey(ByVal pHotKeyID As Integer)
|
||||
If _HotkeyIDList.ContainsKey(pHotKeyID) = False Then
|
||||
Exit Sub
|
||||
End If
|
||||
|
||||
Dim oHotkeyId As Short = _HotkeyIDList(pHotKeyID)
|
||||
_HotkeyIDList.Remove(pHotKeyID)
|
||||
_HotkeyList.Remove(oHotkeyId)
|
||||
NativeMethods.UnregisterHotKey(_OwnerForm.Handle, CInt(oHotkeyId))
|
||||
NativeMethods.GlobalDeleteAtom(oHotkeyId)
|
||||
End Sub
|
||||
|
||||
Private Function PreFilterMessage(ByRef m As Message) As Boolean Implements IMessageFilter.PreFilterMessage
|
||||
If m.Msg = NativeMethods.WM_HOTKEY Then
|
||||
If Clipboard.GetText().Trim() <> String.Empty Then
|
||||
RaiseEvent HotKeyPressed(_HotkeyList(CShort(m.WParam)).HotKeyID)
|
||||
End If
|
||||
End If
|
||||
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
|
||||
|
||||
Sub New(ByVal NewHotKey As Keys, ByVal NewModifier As ModfierKey, ByVal NewHotKeyID As String)
|
||||
HotKey = NewHotKey
|
||||
Modifier = NewModifier
|
||||
HotKeyID = NewHotKeyID
|
||||
End Sub
|
||||
End Class
|
||||
End Class
|
||||
@@ -31,5 +31,5 @@ Imports System.Runtime.InteropServices
|
||||
' übernehmen, indem Sie "*" eingeben:
|
||||
' <Assembly: AssemblyVersion("1.0.*")>
|
||||
|
||||
<Assembly: AssemblyVersion("1.0.0.0")>
|
||||
<Assembly: AssemblyFileVersion("1.0.0.0")>
|
||||
<Assembly: AssemblyVersion("1.1.0.0")>
|
||||
<Assembly: AssemblyFileVersion("1.1.0.0")>
|
||||
|
||||
@@ -79,6 +79,27 @@ Public Class NativeMethods
|
||||
Public Shared Function GetCursorPos(ByRef lpPoint As PointAPI) As <MarshalAs(UnmanagedType.Bool)> Boolean
|
||||
End Function
|
||||
|
||||
Public Declare Function RegisterHotKey Lib "user32" (
|
||||
ByVal Hwnd As IntPtr,
|
||||
ByVal ID As Integer,
|
||||
ByVal Modifiers As Integer,
|
||||
ByVal Key As Integer
|
||||
) As Integer
|
||||
|
||||
Public Declare Function UnregisterHotKey Lib "user32" (
|
||||
ByVal Hwnd As IntPtr,
|
||||
ByVal ID As Integer
|
||||
) As Integer
|
||||
|
||||
Public Declare Auto Function GetWindowText Lib "user32" (
|
||||
ByVal hWnd As IntPtr,
|
||||
ByVal lpString As StringBuilder,
|
||||
ByVal cch As Integer
|
||||
) As Integer
|
||||
|
||||
Public Declare Function GlobalAddAtom Lib "kernel32" Alias "GlobalAddAtomA" (ByVal IDString As String) As Short
|
||||
Public Declare Function GlobalDeleteAtom Lib "kernel32" (ByVal Atom As Short) As Short
|
||||
|
||||
Public Const STANDARD_RIGHTS_REQUIRED As Integer = &HF0000
|
||||
Public Const SECTION_QUERY As Short = &H1
|
||||
Public Const SECTION_MAP_WRITE As Short = &H2
|
||||
@@ -104,6 +125,7 @@ Public Class NativeMethods
|
||||
Public Const SEE_MASK_INVOKEIDLIST = &HC
|
||||
Public Const SEE_MASK_NOCLOSEPROCESS = &H40
|
||||
Public Const SEE_MASK_FLAG_NO_UI = &H400
|
||||
Public Const WM_HOTKEY As Integer = &H312
|
||||
|
||||
Public Enum PageProtection As UInteger
|
||||
NoAccess = &H1
|
||||
|
||||
@@ -76,6 +76,7 @@
|
||||
<ItemGroup>
|
||||
<Compile Include="Drawing.vb" />
|
||||
<Compile Include="File.vb" />
|
||||
<Compile Include="Hotkey.vb" />
|
||||
<Compile Include="NativeMethods.vb" />
|
||||
<Compile Include="Utils.vb" />
|
||||
<Compile Include="Window.vb" />
|
||||
|
||||
Reference in New Issue
Block a user