Advertisement
Guest User

WIP macro median XL

a guest
Jun 16th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #singleInstance Force
  2.  
  3. ;****************************************************************************
  4. ;* TODO *********************************************************************
  5. ;****************************************************************************
  6. /*       === Objectively  ===                   === Subjectively ===
  7.         1 GUI                                  1 Check active window
  8.         2 Tray                                 2
  9. */
  10. ;****************************************************************************
  11. ;* Startup ******************************************************************
  12. ;****************************************************************************
  13. SendMode Input
  14.  
  15. ;myIni := A_ScriptDir "\" "conf.ini"
  16. confDir = %A_ScriptDir%\QC_Conf
  17.  
  18.  
  19. ; checking for config files
  20. if ! ( fileExist(confDir "\config.ini") == "A" )
  21. {   ; Default config file
  22.     fileCreateDir, % confDir
  23.     iniwrite template.ini,%confDir%\config.ini, main, activeLayout
  24.     ; default skill template
  25.     myIni = %confDir%\template.ini
  26.  
  27.     suspendKey = SC029
  28.     termKey = !ESC
  29.  
  30.  
  31.     KeyList   := ["~F1","~F2","~F3","~F4","~F5","~F6","~F7","~F8"]
  32.     QuickKeys := ["~F5","~F6"]
  33.     Toggled   := ["^LALT"]
  34.  
  35.     Rebound      := []
  36.     Rebound[0,0] := "~F"
  37.     Rebound[0,1] := "F3"
  38.     Rebound[1,0] := "~SPACE"
  39.     Rebound[1,1] := "F5"
  40.     Rebound[2,0] := "~E"
  41.     Rebound[2,1] := "F6"
  42.     Rebound[3,0] := "RBUTTON"
  43.     Rebound[3,1] := "F2"
  44.     Rebound[4,0] := "+RBUTTON"
  45.     Rebound[4,1] := "F1"
  46.  
  47.     toIni("# Default settings for " A_ScriptName )
  48.     iniWrite % suspendKey, % myIni, core, SuspendKey
  49.     iniWrite % termKey,    % myIni, core, termKey
  50.     iniWrite % arr2String(Toggled),   % myIni, hotkeys, Toggled
  51.     iniWrite % arr2String(KeyList),   % myIni, hotkeys, KeyList
  52.     iniWrite % arr2String(QuickKeys), % myIni, hotkeys, QuickKeys
  53.     for a, b in Rebound
  54.         IniWrite % Rebound[a,0] ">" Rebound[a,1], % myIni, reboundkeys, % a
  55.  
  56.     msgbox, config directory created at`n%confDir%`n`nClosing
  57.           , Please restart
  58.           exitapp
  59. } else
  60. { iniRead myIni, %confDir%\config.ini, main, activeLayout
  61.     myIni := confDir "\" myIni
  62.  
  63.     iniRead suspendKey, % myIni, core, SuspendKey
  64.     iniRead termKey, % myIni, core, termKey
  65.  
  66.     iniRead xtmp, % myIni, hotkeys, KeyList
  67.     keylist := []
  68.     loop, parse, xtmp, "|", %A_Space%%A_Tab%
  69.         KeyList[A_Index] := A_LoopField
  70.  
  71.     iniRead xtmp, % myIni, hotkeys, QuickKeys
  72.     QuickKeys := []
  73.     loop, parse, xtmp, "|", %A_Space%%A_Tab%
  74.         QuickKeys[A_Index] := A_LoopField
  75.  
  76.     rebound := []
  77.     loop 8
  78.     {   iniRead xtmp, % myIni, reboundkeys, % A_Index-1
  79.         if ( xtmp ~= "ERROR" )
  80.             break
  81.         rebound[A_Index-1] := []
  82.         rebound[A_Index-1,0] := regExReplace(xtmp,">.*$","")
  83.         rebound[A_Index-1,1] := regExReplace(xtmp,"^.*>","")
  84.     }
  85.  
  86.     iniRead xtmp, % myIni, hotkeys, Toggled
  87.         Toggled := []
  88.         loop, parse, xtmp, "|", %A_Space%%A_Tab%
  89.             Toggled[A_Index] := A_LoopField
  90.  
  91.     xtmp := "", temp := "", temp0 := "", temp1 := ""
  92. }
  93.  
  94. ;****************************************************************************
  95. ;* Binding hotkeys **********************************************************
  96. ;****************************************************************************
  97.  
  98. outer:
  99. for a, b in KeyList
  100. {   for b, c in QuickKeys
  101.     {   if KeyList[a] == QuickKeys[b]
  102.         {   hotkey, % KeyList[a], Bound, Enable
  103.             continue outer
  104.         }
  105.     } hotkey, % "~" KeyList[a], UnBound, Enable
  106. }
  107.  
  108. for a, b in rebound
  109. {   xtmp := regExReplace(rebound[a,0],"~","")
  110.     xtmp := regExReplace(xtmp,"\+","a")
  111.     xtmp := regExReplace(xtmp,"!","b")
  112.     xtmp := regExReplace(xtmp,"\^","c")
  113.     %xtmp%act := rebound[a,1]
  114.     hotkey, % rebound[a,0], testRebind, Enable
  115. }
  116.  
  117. for a, b in Toggled
  118.     hotkey, % Toggled[a], TogKey, Enable
  119.  
  120. hotkey, % "~" suspendKey, suspendMe, Enable
  121. hotkey, % "~" termKey, killme, Enable
  122.  
  123. Return ; End of Startup
  124.  
  125. ;****************************************************************************
  126. ;* Hotkey actions ***********************************************************
  127. ;****************************************************************************
  128. UnBound: ; Every click of KeyList keys is saved as last active
  129.     lastKey := regExReplace(A_ThisHotkey,"\W?","")
  130.     return
  131.  
  132. Bound: ; Bound are thy QuickKeys
  133.     thiskey := regExReplace(A_ThisHotkey,"\W?","")
  134.     send {%thiskey%}
  135.     send {RBUTTON DOWN}
  136.     keywait %thiskey%
  137.     send {RBUTTON UP}
  138.     send {%lastKey%}
  139.     return
  140.  
  141. testRebind: ; This is a terrible idea
  142.     thisKey := regExReplace(A_ThisHotkey,"~","")
  143.     thisKey := regExReplace(thisKey,"\+","a")
  144.     thisKey := regExReplace(thisKey,"!","b")
  145.     thisKey := regExReplace(thisKey,"\^","c")
  146.     xtmp := % ( thisKey . "act" ) ;variable that holds rebound[x,1]
  147.     xtmp := %xtmp% ; translated into rebound[x,1]
  148.     send {%xtmp%} ; sent
  149.     send {RBUTTON DOWN}
  150.     keywait % regExReplace(A_ThisHotkey,"\W","")
  151.     send {RBUTTON UP}
  152.     send {%lastKey%}
  153.     return
  154.  
  155. togKey:
  156.     thisKey := regExReplace(A_ThisHotkey,"\W?","")
  157.     if tog%thisKey% := ! tog%thisKey%
  158.         send {%thisKey% DOWN}
  159.     else
  160.         send {%thisKey% UP}
  161.     return
  162.  
  163. suspendMe:
  164.     suspend
  165.     return
  166.  
  167. killme:
  168.     exitapp
  169.  
  170. ;****************************************************************************
  171. ;* Functions ****************************************************************
  172. ;****************************************************************************
  173. arr2String(byref tBody)
  174. {   for key, obj in tBody
  175.         aTip := aTip . tBody[key] ( tBody[key+1] != "" ? "|" : "" )
  176.     return aTip
  177. }
  178.  
  179. toIni(text)
  180. {   Global myIni
  181.     FileAppend, % text "`n", % myIni
  182. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement