Attribute VB_Name = "HotKeyModule"
Option Explicit
Private Declare Function RegisterHotKey Lib "user32" _
    (ByVal hwnd As Long, ByVal id As Long, _
    ByVal fsModifiers As Long, ByVal vk As Long) As Long
Private Declare Function UnregisterHotKey Lib "user32" _
    (ByVal hwnd As Long, ByVal id As Long) As Long

Private Const MOD_ALT = &H1
Private Const MOD_CONTROL = &H2
Private Const MOD_SHIFT = &H4
Private Const VK_ADD = &H6B
Private Const VK_ATTN = &HF6
Private Const VK_BACK = &H8
Private Const VK_CANCEL = &H3
Private Const VK_CAPITAL = &H14
Private Const VK_CLEAR = &HC
Private Const VK_CONTROL = &H11
Private Const VK_CRSEL = &HF7
Private Const VK_DECIMAL = &H6E
Private Const VK_DELETE = &H2E
Private Const VK_DIVIDE = &H6F
Private Const VK_DOWN = &H28
Private Const VK_END = &H23
Private Const VK_EREOF = &HF9
Private Const VK_ESCAPE = &H1B
Private Const VK_EXECUTE = &H2B
Private Const VK_EXSEL = &HF8
Private Const VK_F1 = &H70
Private Const VK_F10 = &H79
Private Const VK_F11 = &H7A
Private Const VK_F12 = &H7B
Private Const VK_F13 = &H7C
Private Const VK_F14 = &H7D
Private Const VK_F15 = &H7E
Private Const VK_F16 = &H7F
Private Const VK_F17 = &H80
Private Const VK_F18 = &H81
Private Const VK_F19 = &H82
Private Const VK_F2 = &H71
Private Const VK_F20 = &H83
Private Const VK_F21 = &H84
Private Const VK_F22 = &H85
Private Const VK_F23 = &H86
Private Const VK_F24 = &H87
Private Const VK_F3 = &H72
Private Const VK_F4 = &H73
Private Const VK_F5 = &H74
Private Const VK_F6 = &H75
Private Const VK_F7 = &H76
Private Const VK_F8 = &H77
Private Const VK_F9 = &H78
Private Const VK_HELP = &H2F
Private Const VK_HOME = &H24
Private Const VK_INSERT = &H2D
Private Const VK_LBUTTON = &H1
Private Const VK_LCONTROL = &HA2
Private Const VK_LEFT = &H25
Private Const VK_LMENU = &HA4
Private Const VK_LSHIFT = &HA0
Private Const VK_MBUTTON = &H4             '  NOT contiguous with L RBUTTON
Private Const VK_MENU = &H12
Private Const VK_MULTIPLY = &H6A
Private Const VK_NEXT = &H22
Private Const VK_NONAME = &HFC
Private Const VK_NUMLOCK = &H90
Private Const VK_NUMPAD0 = &H60
Private Const VK_NUMPAD1 = &H61
Private Const VK_NUMPAD2 = &H62
Private Const VK_NUMPAD3 = &H63
Private Const VK_NUMPAD4 = &H64
Private Const VK_NUMPAD5 = &H65
Private Const VK_NUMPAD6 = &H66
Private Const VK_NUMPAD7 = &H67
Private Const VK_NUMPAD8 = &H68
Private Const VK_NUMPAD9 = &H69
Private Const VK_OEM_CLEAR = &HFE
Private Const VK_PA1 = &HFD
Private Const VK_PAUSE = &H13
Private Const VK_PLAY = &HFA
Private Const VK_PRINT = &H2A
Private Const VK_PRIOR = &H21
Private Const VK_PROCESSKEY = &HE5
Private Const VK_RBUTTON = &H2
Private Const VK_RCONTROL = &HA3
Private Const VK_RETURN = &HD
Private Const VK_RIGHT = &H27
Private Const VK_RMENU = &HA5
Private Const VK_RSHIFT = &HA1
Private Const VK_SCROLL = &H91
Private Const VK_SELECT = &H29
Private Const VK_SHIFT = &H10
Private Const VK_SNAPSHOT = &H2C
Private Const VK_SPACE = &H20
Private Const VK_SUBTRACT = &H6D
Private Const VK_TAB = &H9
Private Const VK_UP = &H26
Private Const VK_ZOOM = &HFB
Private Const MOD_WIN = &H8

Private Const GWL_WNDPROC = (-4)
Private Const WM_HOTKEY = &H312

Private Declare Sub CopyMemoryH Lib "kernel32" Alias "RtlMoveMemory" (ByRef Destination As Any, ByVal Source As Any, ByVal Length As Long)
Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long


Private Declare Function GetCurrentProcessId Lib "kernel32" () As Long
Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long



'HOTKEYS ACTION--------------------------------
Private Const HK_SCRIPT = 1
Private Const HK_KILLACTIVEPROCESS = 2
Private Const HK_CLOSEACTIVEWINDOW = 3
'HOTKEYS ACTION--------------------------------


Public lngOldWindowProc As Long

Public Sub ActivateHotkey(ByVal eChoice As Boolean)
    If eChoice = True Then
        RegisterHotKey 0, HK_SCRIPT, MOD_CONTROL + MOD_WIN, vbKeyS
        RegisterHotKey 0, HK_KILLACTIVEPROCESS, MOD_CONTROL + MOD_WIN, vbKeyDelete
        RegisterHotKey 0, HK_CLOSEACTIVEWINDOW, MOD_CONTROL + MOD_WIN, vbKeyEscape
        lngOldWindowProc = SetWindowLong(0, GWL_WNDPROC, AddressOf SubProc)
    Else
        UnregisterHotKey 0, HK_SCRIPT
        UnregisterHotKey 0, HK_KILLACTIVEPROCESS
        UnregisterHotKey 0, HK_CLOSEACTIVEWINDOW
        Call SetWindowLong(0, GWL_WNDPROC, lngOldWindowProc)
    End If
End Sub

Public Function SubProc(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    Dim lValue As Long
    Dim lValue2 As Long
    Dim sValue As String
    If wMsg = WM_HOTKEY Then    'the hotkey message was fired
        'SHOW SCRIPT -------------------------------------------
        If LoWord(lParam) = (MOD_CONTROL + MOD_WIN) And HiWord(lParam) = vbKeyS And wParam = HK_SCRIPT Then
            
        End If
        'SHOW SCRIPT -------------------------------------------
        
        'KILL ACTIVE PROCESS -----------------------------------
        If LoWord(lParam) = (MOD_CONTROL + MOD_WIN) And HiWord(lParam) = vbKeyDelete And wParam = HK_KILLACTIVEPROCESS Then
            
        End If
        'KILL ACTIVE PROCESS -----------------------------------
        
        'KILL ACTIVE WINDOW ------------------------------------
        If LoWord(lParam) = (MOD_CONTROL + MOD_WIN) And HiWord(lParam) = vbKeyEscape And wParam = HK_CLOSEACTIVEWINDOW Then
            
        End If
        'KILL ACTIVE WINDOW ------------------------------------
        
    End If
    SubProc = CallWindowProc(lngOldWindowProc, hwnd, wMsg, wParam, lParam)
End Function

Public Function LoWord(ByVal dw As Long) As Integer
    On Error GoTo Err_LoWord
    CopyMemoryH LoWord, ByVal VarPtr(dw), 2
Exit_LoWord:
    Exit Function
Err_LoWord:
    GoTo Exit_LoWord
End Function

Public Function HiWord(ByVal dw As Long) As Integer
    On Error GoTo Err_HiWord
    CopyMemoryH HiWord, ByVal VarPtr(dw) + 2, 2
Exit_HiWord:
    Exit Function
Err_HiWord:
    GoTo Exit_HiWord
End Function

