Advertisement
wwww

GunZ Macros (AHK)

Aug 13th, 2013
1,018
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. sleep(period := 1, Mode := "")
  2. {
  3.     static Frequency, MinSetResolution, PID         ; frequency can't change while computer is on
  4.  
  5.     if (Mode = "P")             ; Precise, but the loop will eat CPU cycles! - use for short time periods
  6.     {
  7.         pBatchLines := A_BatchLines
  8.         SetBatchLines, -1       ;   increase the precision
  9. ;       if !PID
  10. ;           PID := DllCall("GetCurrentProcessId")
  11. ;       pPiority := DllCall("GetPriorityClass","UInt", hProc := DllCall("OpenProcess","Uint",0x400,"Int",0,"UInt", PID))    ; have to use 0x400 (PROCESS_QUERY_INFORMATION)
  12. ;                           , DllCall("CloseHandle","Uint",hProc)
  13. ;       if (pPiority != 0x20)  ;  Normal - I figure if priortiy less than normal increase it to normal for accuracy else if its above normal decrease it, so it doesn't affect other programs as much
  14. ;           DllCall("SetPriorityClass","UInt", hProc := DllCall("OpenProcess","Uint",0x200,"Int",0,"UInt",PID), "Uint", 0x20) ; set priority to normal ;have to open a new process handle with 0x200 (PROCESS_SET_INFORMATION)
  15. ;                           , PriorityAltered := True
  16.         if !Frequency
  17.             DllCall("QueryPerformanceFrequency", "Int64*", Frequency)   ; e.g. 3222744 (/s)
  18.         DllCall("QueryPerformanceCounter", "Int64*", Start)
  19.         Finish := Start + ( Frequency * (period/1000))
  20.         loop
  21.             DllCall("QueryPerformanceCounter", "Int64*", Current)       ;   eats the cpu
  22.         until (Current >= Finish)
  23.         SetBatchLines, %pBatchLines%
  24. ;       if PriorityAltered ; restore original priority
  25. ;           DllCall("SetPriorityClass","UInt", hProc := DllCall("OpenProcess","Uint",0x200,"Int",0,"UInt",PID), "Uint", pPiority) ; reset priority
  26. ;               , DllCall("CloseHandle","Uint",hProc)  
  27.  
  28.     }
  29.     else if (Mode = "HP" || Mode = "HS" )       ; hybrid Precise or hybrid suspend
  30.     {                                           ; will sleep the majority of the time using AHKs sleep
  31.         if !Frequency                           ; and sleep the remainder using Precise or suspend
  32.             DllCall("QueryPerformanceFrequency", "Int64*", Frequency)
  33.         DllCall("QueryPerformanceCounter", "Int64*", Start)
  34.         Finish := Start + ( Frequency * (period/1000))
  35.         if (A_BatchLines = -1)
  36.             sleep % period - 15         ; if period is < 15 this will be a nagative number which will simply make AHK check its message queue
  37.         else sleep, % period - 25       ; I picked 25 ms, as AHK sleep is usually accurate to 15 ms, and then added an extra 10 ms in case there was an AHK internal 10ms sleep
  38.         DllCall("QueryPerformanceCounter", "Int64*", Current)
  39.         if (Current < Finish)                       ; so there is still a small amount of sleep time left, lets use the precise methods for the remainder
  40.         {
  41.             period := (Finish - Current)*1000 / Frequency ; convert remainder to ms
  42.             if (Mode = "HP")
  43.                 sleep(period, "P")
  44.             else sleep(period, "S")
  45.         }
  46.     }
  47.     else if (Mode = "S")    ; suspend/sleep (sleeps entire script so will delay timers/hotkeys)
  48.     {
  49.         if !MinSetResolution
  50.         {
  51.             error := DllCall("winmm\timeGetDevCaps", Int64P, TimeCaps, UInt,8)
  52.             if ( error || Errorlevel)
  53.             {
  54.                 DLLcallErrorlevel := Errorlevel
  55.                 sleep, %period%         ;fall back to AHKs own sleep
  56.                 return error ? error : DLLcallErrorlevel
  57.             }
  58.             MinSetResolution := TimeCaps & 0xFFFFFFFF
  59.             ;MaxResolution := TimeCaps >> 32
  60.             DllCall("Winmm.dll\timeBeginPeriod", UInt, MinSetResolution)
  61.         }      
  62.         DllCall("Sleep", UInt, period)
  63.     }
  64.     else if (Mode = "Off" && MinSetResolution)      ; this should be called once at the end of the script
  65.     {                                               ; if mode "s" has been used somewhere
  66.         DllCall("Winmm.dll\timeEndPeriod", UInt, MinSetResolution)
  67.         MinSetResolution := False      
  68.     }
  69.     else                        ; When no mode is specified, the function will use the precise method when the period
  70.     {                           ; is 20 ms or less (i have a number of sleep calls which contain a variable period)
  71.         if (period > 20)        ; otherwise it just uses AHKs sleep
  72.             sleep, %period%
  73.         else sleep(period, "P")
  74.     }
  75.     return
  76. }
  77.  
  78.  
  79. /*
  80. MSDN:
  81. Use caution when calling timeBeginPeriod, as frequent calls can significantly affect the system clock,
  82. system power usage, and the scheduler. If you call timeBeginPeriod, call it one time early in the application
  83. and be sure to call the timeEndPeriod function at the very end of the application.
  84.  
  85. */
  86.  
  87. SetBatchLines, -1
  88.  
  89. #IfWinActive ahk_class RealSpace2
  90.  
  91. ; Dash spam
  92. LCtrl::
  93.     While (GetKeyState("LCtrl", "P"))
  94.     {
  95.         If (GetKeyState("w", "P"))
  96.         {
  97.             SendInput, {w down}
  98.             sleep(1, "s")
  99.             SendInput, {w up}
  100.             SendInput, {w down}
  101.             sleep(1, "s")
  102.             SendInput, {w up}
  103.         }
  104.         If (GetKeyState("a", "P"))
  105.         {
  106.             SendInput, {a down}
  107.             sleep(1, "s")
  108.             SendInput, {a up}
  109.             SendInput, {a down}
  110.             sleep(1, "s")
  111.             SendInput, {a up}
  112.         }
  113.         If (GetKeyState("s", "P"))
  114.         {
  115.             SendInput, {s down}
  116.             sleep(1, "s")
  117.             SendInput, {s up}
  118.             SendInput, {s down}
  119.             sleep(1, "s")
  120.             SendInput, {s up}
  121.         }
  122.         If (GetKeyState("d", "P"))
  123.         {
  124.             SendInput, {d down}
  125.             sleep(1, "s")
  126.             SendInput, {d up}
  127.             SendInput, {d down}
  128.             sleep(1, "s")
  129.             SendInput, {d up}
  130.         }
  131.     }
  132. Return
  133.  
  134. ; Stab spam
  135. NumpadEnd::
  136.     While (GetKeyState("NumpadEnd", "P"))
  137.     {
  138.         SendInput, {LButton down}
  139.         sleep(1, "s")
  140.         SendInput, {LButton up}
  141.     }
  142. Return
  143.  
  144. ; Dash Stab (Forward)
  145. NumpadDown::
  146.     While (GetKeyState("NumpadDown", "P"))
  147.     {
  148.         SendInput, {w down}
  149.         sleep(1, "s")
  150.         SendInput, {w up}
  151.         SendInput, {w down}
  152.         SendInput, {LButton down}
  153.         sleep(1, "s")
  154.         SendInput, {w up}
  155.         SendInput, {LButton up}
  156.     }
  157. Return
  158.  
  159. ; Dash Stab (Back)
  160. NumpadPgDn::
  161.     While (GetKeyState("NumpadPgDn", "P"))
  162.     {
  163.         SendInput, {s down}
  164.         sleep(1, "s")
  165.         SendInput, {s up}
  166.         SendInput, {s down}
  167.         SendInput, {LButton down}
  168.         sleep(1, "s")
  169.         SendInput, {s up}
  170.         SendInput, {LButton up}
  171.     }
  172. Return
  173.  
  174. ; Dash Stab (Disco)
  175. NumpadLeft::
  176.     While (GetKeyState("NumpadLeft", "P"))
  177.     {
  178.         SendInput, {w down}
  179.         sleep(1, "s")
  180.         SendInput, {w up}
  181.         SendInput, {w down}
  182.         SendInput, {LButton down}
  183.         sleep(1, "s")
  184.         SendInput, {w up}
  185.         SendInput, {LButton up}
  186.         SendInput, {a down}
  187.         sleep(1, "s")
  188.         SendInput, {a up}
  189.         SendInput, {a down}
  190.         SendInput, {LButton down}
  191.         sleep(1, "s")
  192.         SendInput, {a up}
  193.         SendInput, {LButton up}
  194.         SendInput, {s down}
  195.         sleep(1, "s")
  196.         SendInput, {s up}
  197.         SendInput, {s down}
  198.         SendInput, {LButton down}
  199.         sleep(1, "s")
  200.         SendInput, {s up}
  201.         SendInput, {LButton up}
  202.         SendInput, {d down}
  203.         sleep(1, "s")
  204.         SendInput, {d up}
  205.         SendInput, {d down}
  206.         SendInput, {LButton down}
  207.         sleep(1, "s")
  208.         SendInput, {d up}
  209.         SendInput, {LButton up}
  210.     }
  211. Return
  212.  
  213. ; Block Spam
  214. NumpadClear::
  215.     While (GetKeyState("NumpadClear", "P"))
  216.     {
  217.         SendInput, {LShift down}
  218.         SendInput, {e down}
  219.         sleep(1, "s")
  220.         SendInput, {LShift up}
  221.         SendInput, {e up}
  222.         sleep(1, "s")
  223.     }
  224. Return
  225.  
  226. ; Weapon Spam
  227. NumpadRight::
  228.     While (GetKeyState("NumpadRight", "P"))
  229.     {
  230.         SendInput, {2 down}
  231.         sleep(1, "s")
  232.         SendInput, {2 up}
  233.         SendInput, {1 down}
  234.         sleep(1, "s")
  235.         SendInput, {1 up}
  236.     }
  237. Return
  238.  
  239. <!w::
  240.     SendInput, {w down}
  241.     sleep(1, "s")
  242.     SendInput, {w up}
  243.     SendInput, {w down}
  244.     SendInput, {RButton down}
  245.     sleep(1, "s")
  246.     SendInput, {w up}
  247.     SendInput, {RButton up}
  248. Return
  249.  
  250. <!a::
  251.     SendInput, {a down}
  252.     sleep(1, "s")
  253.     SendInput, {a up}
  254.     SendInput, {a down}
  255.     SendInput, {RButton down}
  256.     sleep(1, "s")
  257.     SendInput, {a up}
  258.     SendInput, {RButton up}
  259. Return
  260.  
  261. <!s::
  262.     SendInput, {s down}
  263.     sleep(1, "s")
  264.     SendInput, {s up}
  265.     SendInput, {s down}
  266.     SendInput, {RButton down}
  267.     sleep(1, "s")
  268.     SendInput, {s up}
  269.     SendInput, {RButton up}
  270. Return
  271.  
  272. <!d::
  273.     SendInput, {d down}
  274.     sleep(1, "s")
  275.     SendInput, {d up}
  276.     SendInput, {d down}
  277.     SendInput, {RButton down}
  278.     sleep(1, "s")
  279.     SendInput, {d up}
  280.     SendInput, {RButton up}
  281. Return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement