Advertisement
Guest User

GrinnKeys2.ahk

a guest
Oct 20th, 2012
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.23 KB | None | 0 0
  1. ; This is the start of a hotkey block. I chose to use Win+Q for this hotkey but you might have to
  2. ; change it to suit your own keyboard.
  3. ; http://www.autohotkey.com/docs/Hotkeys.htm#Symbols
  4. #q::
  5. If (HotkeysEnabled == true)
  6. {
  7. HotkeysEnabled := false
  8. HasCroissant := false
  9. MsgBox, , GrinnKeys, Hotkeys turned off, 2
  10. } else {
  11. IfWinExist, Play The Grinns Tale
  12. WinActivate
  13. else
  14. return
  15.  
  16. ;These values are coordinate offsets from the Origin for the item bar hotkeys; the values do not change.
  17. Item0X := 250
  18. ItemsY := 523
  19. ItemWidth := 53
  20.  
  21. ; This is the core of the Anchor system. It requires a picture to be found in the
  22. ; same directory as this script is run from. This is a cropped picture of the Pramin
  23. ; on the top bar that is almost always found in the exact same spot. It allows us to
  24. ; determine where in the window the top/left corner of the game is so we can use the
  25. ; right coordinates for the rest of the code.
  26. ImageSearch, _FoundX, _FoundY, 0, 0, 1300, 700, *25 GTPramin.png
  27.  
  28. if (ErrorLevel == 1)
  29. {
  30. MsgBox, , GrinnKeys, Pramin image not found on screen.
  31. return
  32. } else if (ErrorLevel == 2)
  33. {
  34. MsgBox, , GrinnKeys, GTPramin.png was not found in the script directory
  35. return
  36. }
  37.  
  38. OriginX := _FoundX - 155
  39. OriginY := _FoundY - 0
  40.  
  41. ImageSearch, _FoundX, _FoundY, 0, 500, 1300, 900, *25 *TransBlack GTCroissant.png
  42.  
  43. if (ErrorLevel == 1)
  44. {
  45. MsgBox, , GrinnKeys, Croissant image not found on screen.
  46. HasCroissant := false
  47. } else if (ErrorLevel == 2)
  48. {
  49. MsgBox, , GrinnKeys, GTCroissant.png was not found in the script directory
  50. HasCroissant := false
  51. } else if (ErrorLevel == 0)
  52. {
  53. HasCroissant := true
  54. CroissantX := _FoundX + 15 - OriginX
  55. CroissantY := _FoundY + 15 - OriginY
  56. }
  57.  
  58. HotkeysEnabled := true
  59. if (HasCroissant)
  60. {
  61. MsgBox, , GrinnKeys, Hotkeys turned on `n` Croissant was found. Hotkey 4 is active, 2
  62. } else {
  63. MsgBox, , GrinnKeys, Hotkeys turned on `n` Croissant was not found. Hotkey 4 is inactive, 2
  64. }
  65. }
  66. return
  67.  
  68. ; This line will make these hotkeys only work if our Grinns Tale game is the active window.
  69. #IfWinActive, Play The Grinns Tale
  70. 1::
  71. ; We are only going to go further if the hotkeys are turned on.
  72. ; This allows us to check for our Origin position once instead of on each keypress.
  73. If (HotkeysEnabled == true)
  74. if (DragToMouse(174, 389) == true)
  75. return
  76.  
  77. Send 1
  78. return
  79.  
  80. 2::
  81. ; We are only going to go further if the hotkeys are turned on.
  82. ; This allows us to check for our Origin position once instead of on each keypress.
  83. If (HotkeysEnabled == true)
  84. if (DragToMouse(265, 389) == true)
  85. return
  86.  
  87. Send 2
  88. return
  89.  
  90. 3::
  91. ; We are only going to go further if the hotkeys are turned on.
  92. ; This allows us to check for our Origin position once instead of on each keypress.
  93. If (HotkeysEnabled == true)
  94. if (DragToMouse(357, 389) == true)
  95. return
  96.  
  97. Send 3
  98. return
  99.  
  100. 4::
  101. ; We are only going to go further if the hotkeys are turned on.
  102. ; This allows us to check for our Origin position once instead of on each keypress.
  103. If (HotkeysEnabled == true)
  104. ; This is only a viable option if the croissant was found
  105. If (HasCroissant)
  106. {
  107. if (DragToMouse(CroissantX, CroissantY) == true)
  108. return
  109. }
  110.  
  111. Send 4
  112. return
  113.  
  114. q::
  115. ; Item slot 1
  116. If (HotkeysEnabled == true)
  117. if (useItem(1) == true)
  118. return
  119.  
  120. Send q
  121. return
  122.  
  123. w::
  124. ; Item slot 2
  125. If (HotkeysEnabled == true)
  126. if (useItem(2) == true)
  127. return
  128.  
  129. Send w
  130. return
  131.  
  132. e::
  133. ; Item slot 3
  134. If (HotkeysEnabled == true)
  135. if (useItem(3) == true)
  136. return
  137.  
  138. Send e
  139. return
  140.  
  141. r::
  142. ; Item slot 4
  143. If (HotkeysEnabled == true)
  144. if (useItem(4) == true)
  145. return
  146.  
  147. Send r
  148. return
  149.  
  150. t::
  151. ; Item slot 5
  152. If (HotkeysEnabled == true)
  153. if (useItem(5) == true)
  154. return
  155.  
  156. Send t
  157. return
  158.  
  159. y::
  160. ; Item slot 6
  161. If (HotkeysEnabled == true)
  162. if (useItem(6) == true)
  163. return
  164.  
  165. Send y
  166. return
  167.  
  168. u::
  169. ; Item slot 7
  170. If (HotkeysEnabled == true)
  171. if (useItem(7) == true)
  172. return
  173.  
  174. Send u
  175. return
  176.  
  177. a::
  178. ; shift item list left
  179. If (HotkeysEnabled == true)
  180. if (ClickTheMouse(Item0X + OriginX, ItemsY + OriginY) == true)
  181. return
  182.  
  183. Send a
  184. return
  185.  
  186. s::
  187. ; shift item list right
  188. ; Please ignore the magic numbers here ;.;
  189. ; The X coord is composed of the itembar start, the origin, and JUST LESS than 8 item widths.
  190. ; Why? Because it worked :P And I can't be bothered to get image sizes precise enough to not need
  191. ; the magic number.
  192. If (HotkeysEnabled == true)
  193. if (ClickTheMouse(Item0X - 3 + OriginX + (ItemWidth * 8), ItemsY + OriginY) == true)
  194. return
  195.  
  196. Send s
  197. return
  198.  
  199. #IfWinActive
  200.  
  201. ;handles generic item slot use
  202. useItem(slotnum)
  203. {
  204. global
  205. return DragToMouse(Item0X + (ItemWidth * slotnum), ItemsY)
  206. }
  207.  
  208. ; This is our work horse. Instead of writing this code three times, once for each hotkey we
  209. ; call this function with the X/Y coordinates of the player and it handles the rest.
  210. DragToMouse(_PlayerX, _PlayerY)
  211. {
  212. ; This makes it so that all variable names in this function, unless otherwise declared Local are global.
  213. ; I could also use: global OriginX, OriginY
  214. global
  215. local _MouseX, _MouseY
  216.  
  217. ; Here we ask for the mouse position. We only need the x/y values so we leave the other parts out.
  218. MouseGetPos, _MouseX, _MouseY
  219.  
  220. ; Here we check to see if our mouse position is in the window.
  221. ; This lets us click over to chat and talk without it triggering on 1/2/3
  222. ; so long as the mouse is off the game.
  223. if (_MouseX - OriginX < 0 || _MouseX - OriginX > 1000
  224. || _MouseY - OriginY < 0 || _MouseY - OriginY > 600)
  225. return false
  226.  
  227. ; Now we ask for the drag movement.
  228. MouseClickDrag, Left, _PlayerX + OriginX, _PlayerY + OriginY, _MouseX, _MouseY, DragSpeed
  229.  
  230. return true
  231. }
  232.  
  233. ClickTheMouse(clickPosX, clickPosY)
  234. {
  235. global
  236. local _MouseX, _MouseY
  237.  
  238. MouseGetPos, _MouseX, _MouseY
  239.  
  240. ; Here we check to see if our mouse position is in the window.
  241. ; This lets us click over to chat and talk without it triggering on 1/2/3
  242. ; so long as the mouse is off the game.
  243. if (_MouseX - OriginX < 0 || _MouseX - OriginX > 1000
  244. || _MouseY - OriginY < 0 || _MouseY - OriginY > 600)
  245. return false
  246.  
  247. MouseMove, clickPosX, clickPosY, 0
  248. Click
  249. MouseMove, _MouseX, _MouseY, 0
  250. return true
  251. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement