Advertisement
Crafticus

Minecraft AHK Script

Oct 6th, 2020 (edited)
5,646
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; # Windows Logo Key
  2. ; ! Alt
  3. ; ^ Control
  4. ; + Shift
  5. ; * Fire hotkey even if extra modifiers are held
  6. ; ~ Don't block native function
  7.  
  8. ;==================================================================================================
  9. ; AHK setting
  10. #NoEnv
  11. SetBatchLines -1
  12. SetTitleMatchMode 2
  13. #SingleInstance Force
  14. SetWorkingDir %A_ScriptDir%
  15.  
  16.  
  17. ; Initialize SoundPlay to remove delay
  18. SoundPlay, ""
  19. ;==================================================================================================
  20. ; Globle values
  21. wintitle := Minecraft X-AHK V0.4
  22. targettitle := none
  23. TARGET_WIN_CLASS := GLFW30 ; Class of a Java program
  24. ModeText := Empty
  25. id := 0
  26.  
  27. ProgState := 0
  28. autoSwing := 0
  29. switchClickEnabled := 0
  30.  
  31. ;===================================================================================================
  32. ;Shortcuts
  33. ;===================================================================================================
  34. Hotkey  !^s,    Stop
  35. Hotkey  !^w,    SelectWindow    ; Allows user to select active window
  36. Hotkey  F8,     KillScript
  37.  
  38. Return
  39.  
  40. KillScript:
  41. {
  42.     ExitApp
  43. }
  44.  
  45. ;===================================================================================================
  46. ; Called when Ctrl+Alt+W is pressed and captures target window information, checks its a java prog
  47. ;and then creates the first window.
  48. SelectWindow:
  49. {
  50.     ;Get mouse pos on screen and grab details of program
  51.     MouseGetPos, , , id, control
  52.     WinGetTitle, targettitle, ahk_id %id%
  53.     WinGetClass, targetclass, ahk_id %id%
  54.     ;MsgBox, ahk_id %id%`nahk_class %targetclass%`n%targettitle%`nControl: %control%
  55.    
  56.     ;Check is Class of program is a Minecraft Java Class
  57.     if InStr(targetclass, TARGET_WIN_CLASS)
  58.     {
  59.         ;Target window found
  60.         ProgState = 2
  61.  
  62.         ; Add some hotkeys that are specific to this window handle
  63.         ; Hotkey  XButton1,   RightClickThrough
  64.  
  65.         Hotkey, IfWinActive, ahk_id %id%
  66.         Hotkey  XButton1,   HoldLeftMouseDown
  67.         Hotkey  XButton2,   HoldRightMouseDown
  68.         Hotkey  F1,         AutoRun
  69.         Hotkey  F4,         SwitchClick
  70.         Hotkey  F5,         EnableSwitchTimer
  71.         Hotkey  ~*s,        AutoRunStop
  72.         Hotkey  ^b,         TowerBuilder
  73.         Hotkey  !^m,        MobGrind
  74.  
  75.         ; clear mouse clicks to target by sending UP to the keys
  76.         ; ControlClick, , ahk_id %id%, ,Right, , NAU
  77.         ; ControlClick, , ahk_id %id%, ,Left, ,NAU
  78.  
  79.         ; Indicate success
  80.         SoundBeep 100
  81.         sleep 500
  82.     }
  83.     Else
  84.     {
  85.         ;Class of target program not a match so give warning message
  86.         MsgBox, You do not seam to have selected a Minecraft window. Please check before you continue.
  87.     }
  88.     Return
  89. }
  90.  
  91. SwitchClick:
  92. {
  93.     ; SoundBeep 400
  94.  
  95.     if (GetKeyState("RButton"))
  96.     {
  97.         Click Right Up
  98.         Sleep 50
  99.         Click Left Down
  100.     }
  101.     Else
  102.     {
  103.         if GetKeyState("LButton")
  104.         {
  105.             Click Left Up
  106.             Sleep 50
  107.         }
  108.  
  109.         Click Right Down
  110.     }
  111.  
  112.     Return
  113. }
  114.  
  115. TowerBuilder:
  116. {
  117.     Click Down Right
  118.     Sleep 50
  119.     Send {Space Down}
  120.     Return
  121. }
  122.  
  123. ; F1
  124. AutoRun:
  125. {
  126.     Send {w down}
  127.     Return
  128. }
  129.  
  130. ; ~*s
  131. AutoRunStop:
  132. {
  133.     if GetKeyState("w")
  134.     {
  135.         Send {w up}
  136.         Send {Click up}
  137.     }
  138.     Return
  139. }
  140.  
  141. ; XButton1
  142. HoldLeftMouseDown:
  143. {
  144.     if GetKeyState("RButton")
  145.     {
  146.         Click Right Up
  147.     }
  148.  
  149.     if (!GetKeyState("LButton"))
  150.         Click Left Down
  151.    
  152.     Return
  153. }
  154.  
  155.  
  156. ; XButton2
  157. HoldRightMouseDown:
  158. {
  159.     if GetKeyState("LButton")
  160.         Click Left Up
  161.  
  162.     if (!GetKeyState("RButton"))
  163.         Click Right Down
  164.  
  165.     Return
  166. }
  167.  
  168.  
  169. ; F5
  170. EnableSwitchTimer:
  171. {
  172.     if (switchClickEnabled > 0)
  173.     {
  174.         switchClickEnabled := 0
  175.     }
  176.     Else
  177.     {
  178.         switchClickEnabled := 1
  179.         heartbeatCount := 0
  180.         SetTimer, Heartbeat, 1000
  181.  
  182.         SoundBeep 200
  183.         SoundBeep 250
  184.         SoundBeep 300
  185.     }
  186.  
  187.     Return
  188. }
  189.  
  190. ;==================================================================================================
  191. ; CTRL+ALT+M
  192. MobGrind:
  193. {
  194.     if (MobGrindActive)
  195.     {
  196.         SoundBeep, 100
  197.     }
  198.     Else
  199.     {
  200.         MobGrindActive := True
  201.         SetTimer, MobGrindTimer, 750 ; 1000 = 1s
  202.  
  203.         SoundBeep 200
  204.         SoundBeep 250
  205.         SoundBeep 300
  206.     }
  207.  
  208.     Return
  209. }
  210.  
  211.  
  212. Heartbeat:
  213. {
  214.     heartbeatCount := heartbeatCount + 1
  215.  
  216.     maxValue := 90
  217.  
  218.     if (GetKeyState("RButton"))
  219.     {
  220.         maxValue := 120
  221.     }
  222.  
  223.     if (heartbeatCount >= maxValue) and (switchClickEnabled > 0)
  224.     {
  225.         heartbeatCount := 0
  226.  
  227.         if (GetKeyState("RButton"))
  228.         {
  229.             Click Right Up
  230.             Sleep 50
  231.             Click Left Down
  232.         }
  233.         Else
  234.         {
  235.             if GetKeyState("LButton")
  236.             {
  237.                 Click Left Up
  238.                 Sleep 50
  239.             }
  240.  
  241.             Click Right Down
  242.         }
  243.     }
  244.  
  245.     Return
  246. }
  247.  
  248.  
  249. MobGrindTimer:
  250. {
  251.     Random, r, 1, 100
  252.     if (r <= 15) or (autoSwing >= 2)
  253.     {
  254.         autoSwing := 0
  255.         ControlClick, , ahk_id %id%, ,Left, ,NAD
  256.         Sleep 50
  257.         ControlClick, , ahk_id %id%, ,Left, ,NAU
  258.     }
  259.     Else
  260.     {
  261.         autoSwing := autoSwing + 1
  262.     }
  263.  
  264.     Return
  265. }
  266.  
  267.  
  268. ;==================================================================================================
  269. ; CTRL+ALT+S
  270. ; Due to mouse loss of focus, STOP will also force mouse keys UP.
  271. Stop:
  272. {
  273.     BreakLoop := 1
  274.    
  275.     MobGrindActive := False
  276.     SetTimer, MobGrindTimer, Off
  277.  
  278.     ControlClick, , ahk_id %id%, ,Right, , NAU
  279.     ControlClick, , ahk_id %id%, ,Left, ,NAU
  280.  
  281.     Sleep 500
  282.  
  283.     Return
  284. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement