Advertisement
TheNoobPolice

Custom Mouse Angle Tilt

Jan 1st, 2023
2,560
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  
  3. Custom Angle Tilt Function test script by TheNoobPolice using Interception driver and EvilC's AHI library.
  4. This is an alternative to Angle Snapping which emulates the directional shift of Independent / By Component accel instead, but without any accel or change in sensitivity.
  5. This gives broader "angular windows" for movements close to each axis, but doesn't completely obfuscate output angles as Snapping does (rather squeezes the input angles needed to hit them).
  6. Desmos demo here: https://www.desmos.com/calculator/hh5yizck9e
  7.  
  8. */
  9. ; =============================================  Load Time ===========================================================================
  10.  
  11. Menu, Tray, NoIcon
  12. #SingleInstance force
  13. ListLines Off
  14. #KeyHistory 0
  15. #NoEnv
  16. #include Lib/AutoHotInterception.ahk
  17. CoordMode, Tooltip, Screen
  18. Suspend, On
  19.  
  20. linked := toggle := hSpread := vSpread := HorSnap := VertSnap := 1
  21. AHI := new AutoHotInterception()
  22.  
  23. for k in AHI.GetDeviceList()
  24.     {
  25.     if (k >= 11) ; first 10 devices are keyboards, 11 to 20 are mice
  26.         NumberOfMice++
  27.     }
  28. Loop % NumberOfMice
  29.     {
  30.     MouseID := 10 + A_Index
  31.     AHI.SubscribeMouseMoveRelative(MouseID, true, Func("MouseLoop").Bind(AHI, MouseID)) ; bind interception object to mouse loop
  32.     }
  33. MouseID := ""
  34. AHI.SetState(0)
  35.  
  36. Process, Priority,, H
  37. SetBatchlines, -1
  38. Msgbox,
  39.     (
  40.     KEYBINDS
  41.     `n`nCapslock  :  Enables / Disables (starts disabled)
  42.     `n`nCtrl + / - or [  ] : Amount of vert/hor angle shift respectively
  43.     `n`nCtrl Home  :  Links / unlinks scaling for both axes
  44.     `n`nCtrl BackSpace  :  Cycles which axes are affected
  45.     `n`nCtrl Esc  :  Closes app and removes all effect on mouse input
  46.     )
  47. Suspend, Off
  48. SetCapsLockState, Off
  49. Menu, Tray, NoStandard
  50. Menu, Tray, Add, Exit, CloseApp
  51. Menu, Tray, Icon
  52. TooltipShow(vSpread, hSpread, toggle)
  53. Return
  54.  
  55. ; ========================================== Run Time  ============================================================================
  56.  
  57.  
  58. ; ------------------------------------------  HotKeys  -----------------------------------------------------------------------
  59.  
  60. ^=::
  61. ^-::
  62.     (A_ThisHotkey == "^=") ? ((vSpread <= 9.9) ? vSpread += 0.1 : vSpread++ ) : ((vSpread <= 10) ? vSpread -= 0.1 : vSpread-- )
  63.     vSpread := (vSpread < 1) ? 1 : vSpread
  64.     if linked
  65.         hSpread := vSpread
  66.     TooltipShow(vSpread, hSpread, toggle)
  67.     Return
  68.    
  69. ^]::
  70. ^[::
  71.     (A_ThisHotkey == "^]") ? ((hSpread <= 9.9) ? hSpread += 0.1 : hSpread++ ) : ((hSpread <= 10) ? hSpread -= 0.1 : hSpread-- )
  72.     hSpread := (hSpread < 1) ? 1 : hSpread
  73.     if linked
  74.         vSpread := hSpread
  75.     TooltipShow(vSpread, hSpread, toggle)
  76.     Return
  77.    
  78. ^BS::
  79.     toggle++
  80.     if (toggle > 3)
  81.         toggle := 1
  82.     Switch (toggle)
  83.         {
  84.         case 1: (HorSnap := VertSnap := true)
  85.         case 2: (HorSnap := true, VertSnap := false)
  86.         case 3: (HorSnap := false, VertSnap := true)
  87.         }
  88.     TooltipShow(vSpread, hSpread, toggle)
  89.     return
  90.    
  91. ^Home Up::linked := !linked, TooltipShow(vSpread, hSpread, toggle)
  92.    
  93. ~*CapsLock Up::GetKeyState("CapsLock", "T") ? AHI.SetState(1) : AHI.SetState(0), TooltipShow(vSpread, hSpread, toggle)
  94.  
  95. ~Esc::TooltipOFF()
  96. ^Esc::CloseApp()
  97.  
  98.  
  99. ; ------------------------------------------------  Functions ----------------------------------------------------------------
  100.  
  101. TooltipShow(vAng, hAng, t){
  102.     global linked
  103.     tooltip, %
  104.     (
  105.     "`nDYNAMIC ANGLE TILT SCRIPT SETTINGS:`n`nGlobal effect is "(GetKeyState("CapsLock", "T") ? "ENABLED" : "DISABLED") "  (Capslock to toggle)`n`nAngle shift (1.0 = no effect):`n`n   Vertical = " round(vAng, 1)",  Ctrl + or - to change`n   Horizontal = " round(hAng, 1)",  Ctrl [ or ] to change`n   (Ctrl Home to link/unlink) State = " (linked ? "linked" : "unlinked") "`n`nAxes affected: (Ctrl Backspace to cycle)`n`n   Vertical = " ((t = 1 || t = 3) ? "On" : "Off") "`n   Horizontal = " ((t = 1 || t = 2) ? "On" : "Off")"`n`nPress Esc to dismiss this tooltip, Ctrl Esc to close app"
  106.     )
  107.     , A_ScreenWidth * 0.8
  108.     , 0
  109. }
  110.    
  111. TooltipOFF(){
  112.     tooltip
  113. }
  114.  
  115. MouseLoop(AHI, MouseID, dx, dy){
  116.     static QuartPi := atan(1), CarryX := 0, CarryY := 0
  117.     global hSpread, vSpread, HorSnap, VertSnap
  118.    
  119.     if (dx && dy) ; if there is some angle
  120.         {
  121.         angle := atan(abs(dy / dx))
  122.         if (angle <= QuartPi)
  123.             HorSnap ? CalculateShift(VertMultiplier, DistanceComp, hSpread, angle, dx, dy) : (VertMultiplier := DistanceComp := 1)
  124.         else
  125.             VertSnap ? CalculateShift(VertMultiplier, DistanceComp, vSpread, angle, dx, dy) : (VertMultiplier := DistanceComp := 1)
  126.         }
  127.     else ; when moving directly horizontally or vertically, no need to take any action
  128.         VertMultiplier := DistanceComp := 1
  129.    
  130.     ; apply to output and carry remainders
  131.     newX := (dx * DistanceComp) + CarryX
  132.     newY := (dy * DistanceComp * VertMultiplier) + CarryY
  133.    
  134.     AHI.Instance.SendMouseMoveRelative(MouseID, round(newX), round(newY))
  135.    
  136.     CarryX := newX - round(newX)
  137.     CarryY := newY - round(newY)
  138. }
  139.  
  140. CalculateShift(ByRef vm, ByRef dc, axis, angle, dx, dy){
  141.     static QuartPiInv := 1 / atan(1)
  142.    
  143.     ; calc a y/x ratio based on input angle (vertical = vSpread, horizontal = 1 / hSpread, 45 degrees = 1)
  144.         vm := axis ** ((QuartPiInv * angle) - 1)
  145.     ; compensate so sensitivity = 1 (we won't change sensitivity due to y component scaling, only angle)
  146.         ScaledY := dy * vm
  147.         dc := sqrt(dx * dx + dy * dy) / sqrt(dx * dx + ScaledY * ScaledY)
  148. }
  149.  
  150. CloseApp(){
  151.     ExitApp
  152. }
  153.  
  154.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement