MS_Initial
This commit is contained in:
50
Global_Indexer/ClassHotkey.vb
Normal file
50
Global_Indexer/ClassHotkey.vb
Normal file
@@ -0,0 +1,50 @@
|
||||
Public Class ClassHotkey
|
||||
|
||||
#Region "Declarations - WinAPI, Hotkey constant and Modifier Enum"
|
||||
''' <summary>
|
||||
''' Declaration of winAPI function wrappers. The winAPI functions are used to register / unregister a hotkey
|
||||
''' </summary>
|
||||
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
|
||||
|
||||
Enum KeyModifier
|
||||
Alt = &H1
|
||||
Control = &H2
|
||||
Shift = &H4
|
||||
Winkey = &H8
|
||||
|
||||
End Enum 'This enum is just to make it easier to call the registerHotKey function: The modifier integer codes are replaced by a friendly "Alt","Shift" etc.
|
||||
#End Region
|
||||
|
||||
|
||||
#Region "Hotkey registration, unregistration and handling"
|
||||
Public Shared Sub registerHotkey(ByRef sourceForm As Form, ByVal hotkeyID As Integer, ByVal triggerKey As String, ByVal modifier As KeyModifier)
|
||||
RegisterHotKey(sourceForm.Handle, hotkeyID, modifier, Asc(triggerKey.ToUpper))
|
||||
End Sub
|
||||
Public Shared Sub unregisterHotkeys(ByRef sourceForm As Form)
|
||||
'Try
|
||||
UnregisterHotKey(sourceForm.Handle, 1) 'Remember to call unregisterHotkeys() when closing your application.
|
||||
UnregisterHotKey(sourceForm.Handle, 2)
|
||||
UnregisterHotKey(sourceForm.Handle, 3)
|
||||
'Catch ex As Exception
|
||||
' ClassLogger.Add("Unerwarteter Fehler in Unregister Hotkeys´: " & ex.Message, True)
|
||||
'End Try
|
||||
|
||||
End Sub
|
||||
'Public Shared Sub handleHotKeyEvent(ByVal hotkeyID As IntPtr)
|
||||
' Select Case hotkeyID
|
||||
' Case 1
|
||||
' MsgBox("The hotkey ALT+W (ID: 1) was pressed")
|
||||
' Case 2
|
||||
' MsgBox("The hotkey ALT+E (ID: 2) was pressed")
|
||||
' Case 3
|
||||
' MsgBox("The hotkey ALT+R (ID: 3) was pressed")
|
||||
' End Select
|
||||
'End Sub
|
||||
#End Region
|
||||
|
||||
End Class
|
||||
Reference in New Issue
Block a user