Advertisement
FireController1847

JoyArrows.ahk

Feb 12th, 2018
405
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Slot = 0
  2. Special = Joy2
  3.  
  4. #Persistent
  5. SetTimer, WatchAxis, 5
  6. SetTimer, WatchRight, 5
  7. SetTimer, WatchLeft, 5
  8. SetTimer, WatchSpace, 5
  9. Return
  10.  
  11. WatchAxis:
  12.  GetKeyState, JoyX, JoyX ; Get position of the X axis
  13.   GetKeyState, JoyY, JoyY ; Get position of the Y axis
  14.   GetKeyState, Joy7, %Special% ; Get select button
  15.   GetKeyState, Joy8, Joy1
  16.   KeyToHoldDownPrev = %KeyToHoldDown% ; Prev now holds the key that was down before (if any).
  17.   KeyToHoldForCompatPrev = %KeyToHoldForCompat%
  18.  
  19.   if (Joy7 == "D") {
  20.     if (JoyX > 70) {
  21.       ; MouseMove, 10, 0, 0.5, R
  22.       DllCall("mouse_event", UInt, 1, int, 15, int, 0) ; Right
  23.     } else if (JoyX < 30) {
  24.       DllCall("mouse_event", UInt, 1, int, -15, int, 0) ; Left
  25.       ; MouseMove, -10, 0, 0.5, R
  26.     } else if (JoyY > 70) {
  27.       DllCall("mouse_event", UInt, 1, int, 0, int, 15) ; Up
  28.     } else if (JoyY < 30) {
  29.       DllCall("mouse_event", UInt, 1, int, 0, int, -15) ; Down
  30.     }
  31.     KeyToHoldDown =
  32.     KeyToHoldForCompat =
  33.   } else if (Joy8 == "D") {
  34.     if (JoyX > 70) {
  35.       ; MouseMove, 10, 0, 0.5, R
  36.       DllCall("mouse_event", UInt, 1, int, 5, int, 0) ; Right
  37.     } else if (JoyX < 30) {
  38.       DllCall("mouse_event", UInt, 1, int, -5, int, 0) ; Left
  39.       ; MouseMove, -10, 0, 0.5, R
  40.     } else if (JoyY > 70) {
  41.       DllCall("mouse_event", UInt, 1, int, 0, int, 5) ; Up
  42.     } else if (JoyY < 30) {
  43.       DllCall("mouse_event", UInt, 1, int, 0, int, -5) ; Down
  44.     }
  45.     KeyToHoldDown =
  46.     KeyToHoldForCompat =
  47.   } else {
  48.     if (JoyX > 70) {
  49.       KeyToHoldDown = Right ; Right or D
  50.       KeyToHoldForCompat = D
  51.     } else if (JoyX < 30) {
  52.       KeyToHoldDown = Left ;
  53.       KeyToHoldForCompat = A
  54.     } else if (JoyY > 70) {
  55.       KeyToHoldDown = Down
  56.       KeyToHoldForCompat = S
  57.     } else if (JoyY < 30) {
  58.       KeyToHoldDown = Up
  59.       KeyToHoldForCompat = W
  60.     } else {
  61.       KeyToHoldDown =
  62.       KeyToHoldForCompat =
  63.     }
  64.   }
  65.  
  66.   if KeyToHoldDown = %KeyToHoldDownPrev%  ; The correct key is already down (or no key is needed).
  67.     Return  ; Do nothing.
  68.  
  69.   ; Otherwise, release the previous key and press down the new key:
  70.   SetKeyDelay -1  ; Avoid delays between keystrokes.
  71.   if KeyToHoldDownPrev {   ; There is a previous key to release.
  72.     Send, {%KeyToHoldDownPrev% up}  ; Release it.
  73.     Send, {%KeyToHoldForCompatPrev% up}
  74.   }
  75.   if KeyToHoldDown {   ; There is a key to press down.
  76.     Send, {%KeyToHoldDown% down}  ; Press it down.
  77.     Send, {%KeyToHoldForCompat% down}
  78.   }
  79. Return
  80.  
  81. WatchRight:
  82.  GetKeyState, Joy6, Joy6 ; Get left click (right trigger)
  83.   GetKeyState, Joy7, %Special% ; Get select button
  84.   KeyToHoldDownRightPrev = %KeyToHoldDownRight% ; Prev now holds the key that was down before (if any).
  85.  
  86.   if (Joy7 == "D") {
  87.     KeyToHoldDownRight =
  88.   } else {
  89.     if (Joy6 == "D") {
  90.       KeyToHoldDownRight = LButton
  91.     } else {
  92.       KeyToHoldDownRight =
  93.     }
  94.   }
  95.  
  96.   if KeyToHoldDownRight = %KeyToHoldDownRightPrev%  ; The correct key is already down (or no key is needed).
  97.     Return  ; Do nothing.
  98.  
  99.   ; Otherwise, release the previous key and press down the new key:
  100.   SetKeyDelay -1  ; Avoid delays between keystrokes.
  101.   if KeyToHoldDownRightPrev {   ; There is a previous key to release.
  102.     Send, {%KeyToHoldDownRightPrev% up}  ; Release it.
  103.   }
  104.   if KeyToHoldDownRight {
  105.     Send, {%KeyToHoldDownRight% down}
  106.   }
  107. Return
  108.  
  109. WatchLeft:
  110.  GetKeyState, Joy5, Joy5 ; Get right click (left trigger)
  111.   GetKeyState, Joy7, %Special% ; Get select button
  112.   KeyToHoldDownLeftPrev = %KeyToHoldDownLeft% ; Prev now holds the key that was down before (if any).
  113.  
  114.   if (Joy7 == "D") {
  115.     KeyToHoldDownLeft =
  116.   } else {
  117.     if (Joy5 == "D") {
  118.       KeyToHoldDownLeft = RButton
  119.     } else {
  120.       KeyToHoldDownLeft =
  121.     }
  122.   }
  123.  
  124.   if KeyToHoldDownLeft = %KeyToHoldDownLeftPrev%  ; The correct key is already down (or no key is needed).
  125.     Return  ; Do nothing.
  126.  
  127.   ; Otherwise, release the previous key and press down the new key:
  128.   SetKeyDelay -1  ; Avoid delays between keystrokes.
  129.   if KeyToHoldDownLeftPrev {   ; There is a previous key to release.
  130.     Send, {%KeyToHoldDownLeftPrev% up}  ; Release it.
  131.   }
  132.   if KeyToHoldDownLeft {
  133.     Send, {%KeyToHoldDownLeft% down}
  134.   }
  135. Return
  136.  
  137. WatchSpace:
  138.  GetKeyState, Joy3, Joy3 ; Get right click (left trigger)
  139.   GetKeyState, Joy7, %Special% ; Get select button
  140.   KeyToHoldDownSpacePrev = %KeyToHoldDownSpace% ; Prev now holds the key that was down before (if any).
  141.  
  142.   if (Joy7 == "D") {
  143.     KeyToHoldDownSpace =
  144.   } else {
  145.     if (Joy3 == "D") {
  146.       KeyToHoldDownSpace = Space
  147.     } else {
  148.       KeyToHoldDownSpace =
  149.     }
  150.   }
  151.  
  152.   if KeyToHoldDownSpace = %KeyToHoldDownSpacePrev%  ; The correct key is already down (or no key is needed).
  153.     Return  ; Do nothing.
  154.  
  155.   ; Otherwise, release the previous key and press down the new key:
  156.   SetKeyDelay -1  ; Avoid delays between keystrokes.
  157.   if KeyToHoldDownSpacePrev {   ; There is a previous key to release.
  158.     Send, {%KeyToHoldDownSpacePrev% up}  ; Release it.
  159.   }
  160.   if KeyToHoldDownSpace {
  161.     Send, {%KeyToHoldDownSpace% down}
  162.   }
  163. Return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement