Hotkey_Set(_ID, _Keys = "", _Action = "", _Data = "", _Params = "", _Overwrite=0) { If _Data and Not _Action _Action := "function" If _Overwrite or Not Hotkey_Exists(_ID) { If _Keys XML_Set("Hotkey", _ID, "keys", Hotkey_Format(_Keys)) If _Action XML_Set("Hotkey", _ID, "action", _Action) If _Data XML_Set("Hotkey", _ID, "data", _Data) If _Params XML_Set("Hotkey", _ID, "params", _Data) Result := _ID } Else Result := false Return Result } Hotkey_Press(_Keys) { _Keys := Hotkey_Format(_Keys) AllKeys := XML_Find("Hotkey", "keys", _Keys) Loop,% SA_Len(AllKeys) Result := SA_Set(Result, Hotkey_Run(SA_Get(AllKeys, A_Index))) Return Result } Hotkey_Enable(_ID = "") { Single := _ID ? true : false If Single Result := XML_Set("Hotkey", _ID, "@enabled", "1") Else Result := XML_Find("Hotkey", "@enabled", "0", "", "1") Return Result } Hotkey_Disable(_ID = "") { Single := _ID ? true : false If Single { If XML_Get("Hotkey", _ID, "@started") Hotkey_Stop(_ID) Result := XML_Set("Hotkey", _ID, "@enabled", "1") } Else { Started := XML_Find("Hotkey", "@started", "1") Loop,% SA_Len(Started) Hotkey_Stop(SA_Get(Started, A_Index)) Result := XML_Find("Hotkey", "@enabled", "0", "", "1") } Return Result } Hotkey_Start(_ID = "") { Single := _ID ? true : false If Not Single IDs := XML_Find("Hotkey", "@enabled", "1") LoopLen := Single ? 1 : SA_Len(IDs) Loop, %LoopLen% { If Not Single _ID := SA_Get(IDs, A_Index) Keys := XML_Get("Hotkey", _ID, "keys") If Keys and IsLabel("Hotkey_Press") and Not XML_Get("Hotkey", _ID, "@started") { Hotkey, %thisKeys%, Hotkey_Press, On XML_Set("Hotkey", _ID, "@started", "1") } } } Hotkey_Stop(_ID = "") { Single := _ID ? true : false If Not Single IDs := XML_Find("Hotkey", "@started", "1") LoopLen := Single ? 1 : SA_Len(IDs) Loop, %LoopLen% { If Not Single _ID := SA_Get(IDs, A_Index) Keys := XML_Get("Hotkey", _ID, "keys") If Keys { Hotkey, %thisKeys%, Hotkey_Press, Off XML_Set("Hotkey", _ID, "@started", "0") } } } Hotkey_Run(_ID) { Keys := XML_Get("Hotkey", _ID, "keys") Action := XML_Get("Hotkey", _ID, "action") Data := XML_Get("Hotkey", _ID, "data") Params := XML_Get("Hotkey", _ID, "params") If (Action = "function") { Function := Data . "(" . Params . ")" If __findFunc(Function) Result := __expr(Function) } Else If (Action = "label") { If IsLabel(Data) { Gosub %Data% Result := ErrorLevel } } Else If (Action = "launch") { If FileExist(Data) { If Params { RunAs,% SA_Get(Params, "user"),% SA_Get(Params, "password"),% SA_Get(Params, "domain") } Run, %Data%,% SA_Get(Params, "workingdir"), SA_Get(Params, "state"), Result } } Else Result := false } Hotkey_Exists(_ID) { If XML_Get("Hotkey", _ID) Result := true Else Result := false Return Result } Hotkey_Delete(_ID) { Return XML_Delete("Hotkey", _ID) } Hotkey_Format(_Keys) { ID := StringReplace(_Keys, " ", "", true) ID := StringLower(_Keys, "T") Return ID }