kilrain

Functions.ahk

Apr 26th, 2013
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;;;;;;;;;;;;;;;;;;;;;;;;; Includes ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2.  
  3. #SingleInstance force  
  4. #InstallKeybdHook
  5. #InstallMouseHook
  6. #NoEnv
  7. #If !isMouseShown()
  8. if not A_IsAdmin
  9. {
  10.    Run *RunAs "%A_ScriptFullPath%"
  11.    ExitApp
  12. }
  13.  
  14.  
  15.  
  16. ;;;;;;;;;;;;;;;;;;;;;;;;; Keybinds ;;;;;;;;;;;;;;;;;;;;;;;;;;
  17.  
  18. Loop, %A_Appdata%\VideoOptions.cfg, , 1
  19. {
  20.     if(A_LoopFileTimeModified>Rec)
  21.     {
  22.         fileloc=%A_LoopFileFullPath%
  23.                
  24.         Rec=%A_LoopFileTimeModified%
  25.     }
  26. }
  27.     if(fileloc = Error)
  28.     {
  29.         MsgBox, "Could not locate VideoConfig.cfg"  --  Check forums for issues `n Press Ok to close script.
  30.         ExitApp
  31.     }else{
  32.         IniWrite, %fileloc%, c:\DFscript\config.ini, Filepath, Loc
  33.     }
  34.  
  35. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  36. ;;;;;;;;;;;;;;;;;;; XML Parser ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  37. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  38.  
  39. FileRead, configVar, %fileloc%
  40. doc := loadXML(configVar)
  41.  
  42. preset0 := doc.selectSingleNode("/SFConfig/InputBindings0/@Value").text
  43. preset1 := doc.selectSingleNode("/SFConfig/InputBindings1/@Value").text
  44. preset2 := doc.selectSingleNode("/SFConfig/InputBindings2/@Value").text
  45.  
  46. presetSlot := doc.selectSingleNode("/SFConfig/InputPresetSlot/@Value").text
  47. if(presetSlot = "0")
  48. {
  49.     keyLoc := preset0
  50. }else if(presetSlot = "1")
  51. {
  52.     keyLoc := preset1
  53. }else if(presetSlot = "2")
  54. {
  55.     keyLoc := preset2
  56. }
  57.  
  58.  
  59. DisplayNode(nodes, indent=0)
  60. {
  61.     for node in nodes
  62.     {
  63.         if node.nodeName != "#text"
  64.             text .= spaces(indent) node.nodeName ": " node.nodeValue "`n"
  65.         else
  66.             text .= spaces(indent) node.nodeValue "`n"
  67.         if node.hasChildNodes
  68.             text .= DisplayNode(node.childNodes, indent+2)
  69.     }
  70.     return text
  71. }
  72.  
  73. spaces(n)
  74. {
  75.     Loop, %n%
  76.         t .= " "
  77.     return t
  78. }
  79.  
  80. loadXML(ByRef data)
  81. {
  82.     o := ComObjCreate("MSXML2.DOMDocument.6.0")
  83.     o.async := false
  84.     o.loadXML(data)
  85.     return o
  86. }
  87.  
  88. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  89.  
  90. Loc := getIni("c:\DFscript\config.ini", "Filepath", "Loc")
  91. actionL := "Action.TriggerLeftCurrentAction"
  92. actionR := "Action.TriggerRightCurrentAction"
  93.  
  94. quick5 := "Action.ActivateQuickItem5"
  95.  
  96. Lradial1 := "GUI.SelectLeftRadialSlot1"
  97. Lradial2 := "GUI.SelectLeftRadialSlot2"
  98. Lradial3 := "GUI.SelectLeftRadialSlot3"
  99. Lradial4 := "GUI.SelectLeftRadialSlot4"
  100. Lradial5 := "GUI.SelectLeftRadialSlot5"
  101. Lradial6 := "GUI.SelectLeftRadialSlot6"
  102. Lradial7 := "GUI.SelectLeftRadialSlot7"
  103. Lradial8 := "GUI.SelectLeftRadialSlot8"
  104. Rradial1 := "GUI.SelectRightRadialSlot1"
  105. Rradial2 := "GUI.SelectRightRadialSlot2"
  106. Rradial3 := "GUI.SelectRightRadialSlot3"
  107. Rradial4 := "GUI.SelectRightRadialSlot4"
  108. Rradial5 := "GUI.SelectRightRadialSlot5"
  109. Rradial6 := "GUI.SelectRightRadialSlot6"
  110. Rradial7 := "GUI.SelectRightRadialSlot7"
  111. Rradial8 := "GUI.SelectRightRadialSlot8"
  112.  
  113. ;;;;;;;;;;;;;;;;;;;; Functions ;;;;;;;;;;;;;;;;;;;;;;;
  114.  
  115. GetKey(bind, fileLoc)
  116. {
  117.         StringGetPos, startPos, fileLoc, %bind%
  118.         StringTrimLeft, fileloc, fileLoc, startPos
  119.         StringReplace, fileLoc, fileLoc, `,, +, all
  120.         StringReplace, fileLoc, fileLoc, `n, +, all
  121.         Loop, Parse, fileLoc, +, `,
  122.         {
  123.             var%A_Index% := A_LoopField
  124.         }
  125.         ;MsgBox % var1
  126.                 FileRead, keylist, keylist.txt
  127.                 if not ErrorLevel
  128.                 {
  129.                     Loop, Parse, keylist, `~, %A_Space%
  130.                         if RegExMatch(A_LoopField,"^(" var2 ")=(.*)$",found)
  131.                             key1 := found2
  132.                     Loop, Parse, keylist, `~, %A_Space%
  133.                         if RegExMatch(A_LoopField,"^(" var3 ")=(.*)$",found)
  134.                             key2 := found2
  135.                         global key3 := key1 key2
  136.                 }return, %key3%
  137. }
  138.  
  139. isMouseShown()
  140. {
  141. StructSize := A_PtrSize + 16
  142. VarSetCapacity(InfoStruct, StructSize)
  143. NumPut(StructSize, InfoStruct)
  144. DllCall("GetCursorInfo", UInt, &InfoStruct)
  145. Result := NumGet(InfoStruct, 8)
  146.  
  147. if Result
  148. return 1
  149. else
  150. return 0
  151. }
  152.  
  153. say(msg)
  154. {
  155.     global ttsEnabled
  156.     if(ttsEnabled == "true")
  157.     {
  158.         global SAPI
  159.         SAPI.speak(msg,1)
  160.     }
  161. }
  162.  
  163. getIni(config, section, key)
  164. {
  165.     IniRead value, %config%, %section%, %key%
  166.     return value
  167. }
  168.  
  169. global leftAction  := GetKey(actionL, keyLoc)
  170. global rightAction := GetKey(actionR, keyLoc)
  171. spawnMount := GetKey(quick5, keyLoc)
  172.  
  173. autoFire := getIni("c:\DFscript\config.ini", "Togglekeys", "autoFire")
  174. instaCast := getIni("c:\DFscript\config.ini", "Togglekeys", "instaCast")
  175. auto := getIni("c:\DFscript\config.ini", "Togglekeys", "auto")
  176. insta := getIni("c:\DFscript\config.ini", "Togglekeys", "insta")
  177.  
  178.  
  179. mountLeft := getIni("c:\DFscript\config.ini", "Hotkeys", "mountLeft")
  180. mountRight := getIni("c:\DFscript\config.ini", "Hotkeys", "mountRight")
  181.  
  182. ver := getini("c:\DFscript\config.ini", "version", "ver")
  183. mounted := false
  184.  
  185. if(spawnMount)
  186. {
  187. Hotkey, ~%spawnMount%, spawnMount
  188. }
  189. if(mountLeft)
  190. {
  191. Hotkey, %mountLeft%, mountLeft
  192. }
  193. if(mountRight)
  194. {
  195. Hotkey, %mountRIght%, mountRight
  196. }
  197.  
  198. loop, 8
  199. {
  200.     variables := GetKey(Lradial%A_Index%, keyLoc)
  201.     Hotkey, ~%variables%, left1
  202. }
  203. loop, 8
  204. {
  205.     variables := GetKey(Rradial%A_Index%, keyLoc)
  206.     Hotkey, ~%variables%, right1
  207. }
  208. ;;;;;;;;;;;;;;;;;;;;; Set Message ;;;;;;;;;;;;;;;;;;;;;;;;
  209.  
  210. ;keyMsg = Set.
  211. ;say(keyMsg)
  212.  
  213. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  214. ^+LButton::
  215. if(auto == true)
  216. {
  217.     say("auto fire deactivated")
  218.     auto := false
  219. }else{
  220.     say("auto fire activated")
  221.     auto := true
  222. }
  223. return
  224.  
  225. ^+RButton::
  226. if(insta == true)
  227. {
  228.     say("insta cast deactivated")
  229.     insta := false
  230. }else{
  231.     say("insta cast activated")
  232.     insta := true
  233. }
  234. return
  235.  
  236. spawnMount:
  237. mounted := true
  238. return
  239.  
  240. left1:
  241. wheel = 1
  242. mounted := false
  243. return
  244.  
  245.  
  246. right1:
  247. if(insta)
  248. {
  249.     mounted := false
  250.     wheel = 1
  251.     sleep 250
  252.     send, {%rightAction% down}
  253.     sleep 150
  254.     send, {%rightAction% up}
  255.     return
  256. }else{
  257.     mounted := false
  258.     wheel = 2
  259.     return
  260. }
  261.  
  262. ;;;;;;;;;;;;;;;;;;;;;;;;; Action Center ;;;;;;;;;;;;;;;;;;;;;;;;;;;
  263.  
  264. *RButton::
  265. if(mounted)
  266. {
  267.     if(auto)
  268.     {
  269.         Loop
  270.         {
  271.             GetKeyState, press, RButton, P
  272.             If press = U
  273.                 Break
  274.             Send, {%rightAction% down}
  275.             sleep 150
  276.             Send, {%rightAction% up}
  277.             sleep 20
  278.         }
  279.     }else{
  280.         send, {%rightAction% down}
  281.         KeyWait, Rbutton, Up
  282.         send, {%rightAction% up}
  283.         return
  284.     }
  285. }else{
  286.     Send {Rbutton down}
  287.     KeyWait, Rbutton, Up
  288.     Send {Rbutton up}
  289.     return
  290. }
  291.  
  292. *LButton::
  293. if(wheel = 1)
  294. {
  295.     if(auto)
  296.     {
  297.         Loop
  298.         {
  299.             GetKeyState, press, LButton, P
  300.             If press = U
  301.                 Break
  302.             Send, {%leftAction% down}
  303.             sleep 150
  304.             Send, {%leftAction% up}
  305.             sleep 20
  306.         }
  307.     }else{
  308.         send, {%leftAction% down}
  309.         KeyWait, Lbutton, Up
  310.         send, {%leftAction% up}
  311.         return
  312.     }
  313. }else if (wheel = 2)
  314. {
  315.     send, {%rightAction% down}
  316.     KeyWait, Lbutton, Up
  317.     send, {%rightAction% up}
  318.     wheel = 1
  319.     return
  320. }
  321.  
  322. mountLeft:
  323. send, {%leftAction% down}
  324. sleep 100
  325. send, {%leftAction% up}
  326. return
  327.  
  328. mountRight:
  329. send, {%rightAction% down}
  330. sleep 100
  331. send, {%rightAction% up}
  332. return
Advertisement
Add Comment
Please, Sign In to add comment