Shadowspaz

ControllerToMouse.ahk

Jan 28th, 2014
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;Controls:
  2. ;
  3. ;Mouse movement: Left and/or Right analog
  4. ;Left-Click: A
  5. ;Right-Click: B
  6. ;Middle-Click: L3 or R3
  7. ;Arrow Keys: Dpad
  8. ;Enter: Y
  9. ;Scroll: X + Up / X + Down (Dpad)
  10. ;Minimize: LT
  11. ;Maximize: RT
  12. ;Copy: X + LT
  13. ;Paste: X + RT
  14. ;Alt-Tab: LB + Back
  15. ;Play/Pause Music: Start
  16. ;Next/Prev Track: Start + LT / Start + RT
  17. ;
  18. ;Toggle Script: LB + RB + X + A
  19. ;Switch Dominance: RB
  20. ;
  21. #SingleInstance, force
  22. DetectHiddenWindows, on
  23.  
  24. Thread, Interrupt, 0
  25.  
  26. MouseToggle := true
  27. Main = 1Joy
  28. state = on
  29.  
  30. SetHotKeys:
  31.  
  32.   Hotkey, %Main%1, LeftClick, %state%
  33.   Hotkey, %Main%2, RightClick, %state%
  34.   Hotkey, %Main%4, EnterButton, %state%
  35.   Hotkey, %Main%7, AltButton, %state%
  36.   Hotkey, %Main%8, MusicStart, %state%
  37.   Hotkey, %Main%9, L3Click, %state%
  38.   Hotkey, %Main%10, R3Click, %state%
  39.   if MouseToggle
  40.     setTimer, WatchVars, 10
  41.  
  42. return
  43.  
  44.  
  45.  
  46. LeftClick:
  47. Suspend, Permit
  48.   If (GetKeyState(Main . 3) and GetKeyState(Main . 5) and GetKeyState(Main . 6))
  49.   {
  50.  
  51.     MouseToggle := !MouseToggle
  52.     Suspend
  53.     If MouseToggle
  54.       setTimer, WatchVars, 10
  55.   }
  56.   Else If MouseToggle
  57.   {
  58.     MouseClick, Left,,, 1, 0, D
  59.     SetTimer, LeftUp, 10
  60.   }
  61. return
  62.  
  63. LeftUp:
  64.  If GetKeyState(Main . 1)
  65.     return
  66.   MouseClick, Left,,, 1, 0, U
  67.   SetTimer, LeftUp, off
  68. return
  69.  
  70.  
  71.  
  72. RightClick:
  73.  MouseClick, Right,,, 1, 0, D
  74.   SetTimer, RightUp, 10
  75. return
  76.  
  77. RightUp:
  78.  If GetKeyState(Main . 2)
  79.     return
  80.   MouseClick, Right,,, 1, 0, U
  81.   SetTimer, RightUp, off
  82. return
  83.  
  84.  
  85.  
  86. L3Click:
  87. R3Click:
  88.  MouseClick, Middle,,, 1, 0, D
  89.   SetTimer, MiddleUp, 10
  90. return
  91. return
  92.  
  93. MiddleUp:
  94.  If (GetKeyState(Main . 9) or GetKeyState(Main . 10))
  95.     return
  96.   MouseClick, Middle,,, 1, 0, U
  97.   SetTimer, MiddleUp, off
  98. return
  99.  
  100.  
  101.  
  102. EnterButton:
  103.  Send {Enter}
  104. return
  105.  
  106.  
  107.  
  108. MusicStart:
  109.  setTimer, PlayPause, 10
  110. return
  111.  
  112. PlayPause:
  113.  If GetKeyState(Main . 8)
  114.     return
  115.   if !changedTrack
  116.   {
  117.     IfWinExist, MediaMonkey
  118.       Send {Media_Play_Pause}
  119.     else
  120.       Run, MediaMonkey.exe, C:\Program Files (x86)\MediaMonkey
  121.   }    
  122.   changedTrack := false
  123.   setTimer, PlayPause, off
  124. return
  125.  
  126.  
  127.  
  128. ;Alt Tab
  129.  
  130. AltButton:
  131.  If GetKeyState(Main . 5)
  132.   {
  133.     Send {Alt down}
  134.     Send {Tab}
  135.     SetTimer, AltTabbing, 10
  136.   }
  137. return
  138.  
  139. AltTabbing:
  140.  If GetKeyState(Main . 5)
  141.     return
  142.   Send {Alt up}
  143.   SetTimer, AltTabbing, off
  144. return
  145.  
  146.  
  147.  
  148. LeftTrigger:
  149.  If GetKeyState(Main . 8)
  150.   {
  151.     Send {Media_Prev}
  152.     changedTrack := true
  153.     return
  154.   }
  155.   setTimer, LTRelease, 10
  156. return
  157.  
  158. LTRelease:
  159.  If Triggers < 90
  160.   {
  161.     If GetKeyState(Main . 3)
  162.       Send ^c
  163.     else
  164.       WinMinimize, A
  165.     setTimer, LTRelease, off
  166.   }
  167. return
  168.  
  169.  
  170.  
  171. RightTrigger:
  172.  If GetKeyState(Main . 8)
  173.   {
  174.     Send {Media_Next}
  175.     changedTrack := true
  176.     return
  177.   }
  178.   setTimer, RTRelease, 10
  179. return
  180.  
  181. RTRelease:
  182.  If Triggers > 10
  183.   {
  184.     If GetKeyState(Main . 3)
  185.       Send ^v
  186.     else
  187.     {
  188.       WinGet, isMax, MinMax, A
  189.       If isMax <> 1
  190.         WinMaximize, A
  191.       else
  192.         WinRestore, A
  193.     }
  194.     setTimer, RTRelease, off
  195.   }
  196. return
  197.  
  198.  
  199.  
  200. ; Monitors all variable switches
  201.  
  202. WatchVars:
  203.  
  204.   Movement := false
  205.   GetKeyState, xone, %Main%X
  206.   GetKeyState, yone, %Main%Y
  207.   GetKeyState, xtwo, %Main%U
  208.   GetKeyState, ytwo, %Main%R
  209.   GetKeyState, Dpad, %Main%POV
  210.   GetKeyState, Triggers, %Main%Z
  211.   movexone := 0
  212.   moveyone := 0
  213.   movextwo := 0
  214.   moveytwo := 0
  215.  
  216.  
  217. ; Analog 1
  218.  
  219.   If xone > 70
  220.   {
  221.     movexone := (xone-70)/3
  222.     Movement := true
  223.   }
  224.   else If xone < 30
  225.   {
  226.     movexone := (xone-30)/3
  227.     Movement := true
  228.   }
  229.  
  230.   If yone > 70
  231.   {
  232.     moveyone := (yone-70)/3
  233.     Movement := true
  234.   }
  235.   else If yone < 30
  236.   {
  237.     moveyone := (yone-30)/3
  238.     Movement := true
  239.   }
  240.  
  241.  
  242. ; Analog 2
  243.  
  244.   If xtwo > 70
  245.   {
  246.     movextwo := (xtwo-70)
  247.     Movement := true
  248.   }
  249.   else If xtwo < 30
  250.   {
  251.     movextwo := (xtwo-30)
  252.     Movement := true
  253.   }
  254.  
  255.   If ytwo > 70
  256.   {
  257.     moveytwo := (ytwo-70)
  258.     Movement := true
  259.   }
  260.   else If ytwo < 30
  261.   {
  262.     moveytwo := (ytwo-30)
  263.     Movement := true
  264.   }
  265.  
  266.  
  267. ; Moves cursor by analog input
  268.  
  269.   If Movement
  270.   {
  271.     setMouseDelay, -1
  272.     MouseMove, movexone+movextwo, moveyone+moveytwo, 0, R
  273.   }
  274.  
  275.  
  276. ; LT and RT
  277.  
  278.   If Triggers > 90
  279.     goSub, LeftTrigger
  280.  
  281.   If Triggers < 10
  282.     goSub, RightTrigger
  283.  
  284.  
  285. ; DPad Control
  286.  
  287.   SendKeyPrev = %SendKey%
  288.   SendKey =
  289.  
  290.   If (Dpad != -1)
  291.  
  292.   {
  293.     If Dpad between 22500 and 31500
  294.       SendKey = Left
  295.     If Dpad between 9000 and 13500
  296.       SendKey = Right
  297.     If Dpad between 13500 and 22500
  298.     {
  299.       If GetKeyState(Main . 3)
  300.         send {WheelDown}
  301.       else
  302.         SendKey = Down
  303.     }
  304.     If (Dpad > 31500 or Dpad < 4500)
  305.     {
  306.       If GetKeyState(Main . 3)
  307.         send {WheelUp}
  308.       else
  309.         SendKey = Up
  310.     }
  311.   }
  312.  
  313.   if SendKey <> %SendKeyPrev%
  314.   {
  315.     if SendKey <>
  316.       Send {%SendKey% down}
  317.     if SendKeyPrev <>
  318.       Send {%SendKeyPrev% up}
  319.   }
  320.  
  321.   if !MouseToggle
  322.     setTimer, WatchVars, off
  323.  
  324. return
  325.  
  326.  
  327.  
  328. ; Switch dominant controller
  329.  
  330. 1Joy6::
  331. Suspend, Permit
  332.   SwitchDom("1Joy")
  333. return
  334.  
  335. 2Joy6::
  336. Suspend, Permit
  337.   ;msgbox woot
  338.   SwitchDom("2Joy")
  339. return
  340.  
  341. 3Joy6::
  342. Suspend, Permit
  343.   SwitchDom("3Joy")
  344. return
  345.  
  346. 4Joy6::
  347. Suspend, Permit
  348.   SwitchDom("4Joy")
  349. return
  350.  
  351.  
  352.  
  353. SwitchDom(whJoy)
  354. {
  355.   global state = "off"
  356.   gosub, SetHotKeys
  357.   global main = whJoy
  358.   global state = "on"
  359.   gosub, SetHotKeys
  360.   return
  361. }
Advertisement
Add Comment
Please, Sign In to add comment