#include-once #cs ======================================== Local Hot Key Functions By Rob Saunders ============================== Known Issues: - Hotkeys are not disabled while navigating file menus in the windows. - Makes use of three global variables: - $a_LocalHotKey_List - $s_LocalHotKey_ActiveNow - $s_LocalHotKey_ActiveThen ============================== _HotKeyCheckLocal ( [$i_Opt] ) To be continually executed, not unlike GUIGetMsg(). Parameters: $i_Opt If 1: Unsets all HotKeys temporarily. When function called with 0 or 2 it will recheck if hotkeys should be set. If 2: Forces a check. Normally the function will only run a check if it notices a difference in the active window handle. ============================== _HotKeySetLocal ( $h_Wnd, $s_Key, $s_Func _) Sets a hotkey for a specific window handle. Parameters: $h_Wnd Handle for the window you want to assign the hotkeys to. $s_Key The key(s) to be used as the hotkey. Same format as Send(). $s_Func The name of the function to call when the hotkey is pressed. Return Value: Returns an integer representing the hotkey (HotKeyID), for use with the HotKeyToggleLocal function (see below) ============================== _HotKeyToggleLocal ( $i_HotKeyID [, $i_State] ) Enables/Disables a created hotkey. Parameters: $i_HotKeyID Numeric ID returned by HotKeySetLocal() $i_State State to set the hotkey to. 1 = Enabled (default) 0 = Disabled Return Value: If successful, returns the HotKeyID value. Otherwise returns 0, and sets @error: @error 1 Invalid HotKeyID @error 2 Invalid state ============================== #ce Global $a_LocalHotKey_List[1][4] $a_LocalHotKey_List[0][0] = 0 Global $s_LocalHotKey_ActiveNow = '' Global $s_LocalHotKey_ActiveThen = '' Func _HotKeyCheckLocal($i_Opt = 0) Local $i_Opt_PrevVal = Opt('WinTitleMatchMode', 4) $s_LocalHotKey_ActiveNow = WinGetHandle('active') If $i_Opt = 2 OR ($s_LocalHotKey_ActiveNow <> $s_LocalHotKey_ActiveThen) Then For $i = 1 To $a_LocalHotKey_List[0][0] If $i_Opt = 1 AND $a_LocalHotKey_List[$i][3] = 1 Then HotKeySet($a_LocalHotKey_List[$i][1]) $a_LocalHotKey_List[$i][3] = 0 ElseIf $a_LocalHotKey_List[$i][3] = -1 Then ContinueLoop ElseIf NOT $a_LocalHotKey_List[$i][3] AND WinActive($a_LocalHotKey_List[$i][0]) Then HotKeySet($a_LocalHotKey_List[$i][1], $a_LocalHotKey_List[$i][2]) $a_LocalHotKey_List[$i][3] = 1 ElseIf $a_LocalHotKey_List[$i][3] AND NOT WinActive($a_LocalHotKey_List[$i][0]) Then HotKeySet($a_LocalHotKey_List[$i][1]) $a_LocalHotKey_List[$i][3] = 0 EndIf Next EndIf $s_LocalHotKey_ActiveThen = $s_LocalHotKey_ActiveNow Opt('WinTitleMatchMode', $i_Opt_PrevVal) EndFunc Func _HotKeySetLocal($h_Wnd, $s_Key, $s_Func) Local $i_HKCount = $a_LocalHotKey_List[0][0] + 1 ReDim $a_LocalHotKey_List[$i_HKCount + 1][4] $a_LocalHotKey_List[0][0] = $i_HKCount $a_LocalHotKey_List[$i_HKCount][0] = $h_Wnd $a_LocalHotKey_List[$i_HKCount][1] = $s_Key $a_LocalHotKey_List[$i_HKCount][2] = $s_Func $a_LocalHotKey_List[$i_HKCount][3] = 0 Return $i_HKCount EndFunc Func _HotKeyToggleLocal($i_HotKeyID, $i_State = 1) Global $a_LocalHotKey_List If IsNumber($i_HotKeyID) AND $i_HotKeyID > 0 AND $i_HotKeyID <= $a_LocalHotKey_List[0][0] Then If $i_State = 0 Then HotKeySet($a_LocalHotKey_List[$i_HotKeyID][1]) $a_LocalHotKey_List[$i_HotKeyID][3] = -1 ElseIf $i_State = 1 Then $a_LocalHotKey_List[$i_HotKeyID][3] = 0 _HotKeyCheckLocal(2) Else SetError(2) Return 0 EndIf Return $i_HotKeyID Else SetError(1) Return 0 EndIf EndFunc