TheNoobPolice

Lp Norm & Vertical Bias Mouse directional scaling

Jul 12th, 2022 (edited)
522
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. TheNoobPolice's Autohotkey script to generalize mouse input into lp space (outside of acceleration function).
  3.  
  4. See document here: https://docs.google.com/document/d/19vvstC00Lptwc1vuedK1FkBeomteXBa2KgsG3pdyyH8/edit?usp=sharing
  5.  
  6. Requires the Interception driver and evilC's AutoHotInterception library. https://github.com/evilC/AutoHotInterception/releases
  7. Install as per the docs on the GitHub, and copy the library into Documents\Autohotkey\Lib
  8.  
  9. You need to know the VID and PID of the mouse device you are using to test (can be obtained from device manager or the included AHI monitor.ahk script)
  10. Edit those values as shown at the top of the script.
  11.  
  12. Alt + BackSpace to enable / disable the effect on mouse input. Starts disabled.
  13.  
  14. Bracket keys scale the LpNorm Up or Down for diagonal direction scaling. Default is 1 i.e Rectilinear distance. 2 is the "real-life" Euclidean distance, > 10 is the infinity "max" norm
  15.  
  16. -/= keys set bias towards vertical / horizontal direction. Default of 1 (no bias)
  17.  
  18. Ctrl + Esc closes the script and removes any effect on mouse input
  19.  
  20. Currently uses a tooltip to show values / status, I may make this a simple GUI at somepoint but it works ok for now
  21. */
  22.  
  23. VID := 0x1532
  24. PID := 0x0094
  25.  
  26. ListLines Off
  27. #KeyHistory 0
  28. #NoEnv
  29. #SingleInstance force
  30. SetBatchlines, -1
  31. #include <AutoHotInterception>
  32.  
  33. AHI := new AutoHotInterception()
  34. MouseID := AHI.GetMouseId(VID, PID)
  35. Math := {newX :0, newY :0, roundedX :0, roundedY:0, carryX :0, carryY :0, p :1, pInv :1, bias :1, biasInv :1}
  36.  
  37. AHI.SubscribeMouseMoveRelative(MouseID, true, Func("Mouseloop").Bind(AHI, MouseID, Math))
  38. AHI.SetState(0)
  39. Process, Priority,, A
  40. Tooltip, % "Lp Norm disabled - Alt + BackSpace to enable / disable"
  41. SetTimer tooltipOFF, -2000
  42. Return
  43.  
  44. !BS up::
  45.     AHI.SetState((toggle:=!toggle) ? 1 : 0)
  46.     Tooltip, % toggle ? "Lp Norm Active, Lp = " (Math.p) ", Vertical Bias = " (Math.bias) : "Lp Norm disabled"
  47.     SetTimer tooltipOFF, -2000
  48.     return
  49.    
  50. ]::
  51. [::
  52.     if (A_ThisHotkey = "]") {
  53.         if (Math.p >= 3 && Math.p <= 10)
  54.             Math.p ++
  55.         else if (Math.p < 3)
  56.             Math.p := round((Math.p += 0.1), 1)
  57.     }
  58.     else if (A_ThisHotkey = "[") {
  59.         if (Math.p >= 4)
  60.             Math.p --
  61.         else if (Math.p > 1 && Math.p <= 3)
  62.             Math.p := round((Math.p -= 0.1), 1)
  63.     }
  64.     Math.pInv := 1 / Math.p
  65.     TooltipON(round(Math.p, ((Math.p < 3) ? 1 : "")))
  66.     return
  67.    
  68. -::
  69. =::
  70.     if (A_ThisHotkey = "-") {
  71.         if (Math.bias > 0.83)
  72.             Math.bias -= 0.01
  73.     }
  74.     else if (A_ThisHotkey = "=") {
  75.         if (Math.bias < 1.2)
  76.             Math.bias += 0.01
  77.     }
  78.     Math.biasInv := 1 / Math.bias
  79.     TooltipON(Math.bias, 1)
  80.     return
  81.    
  82. TooltipON(Value, vert := 0){
  83.     Tooltip, % vert ? ("Vertical Bias = " Value) : ("Lp Norm = " (Value > 10 ? "Infinity" : Value))
  84.     SetTimer TooltipOFF, -1000
  85. }
  86.     TooltipOFF(){
  87.         Tooltip
  88.     }
  89.    
  90. ^Esc::Exitapp
  91.  
  92. Mouseloop(AHI, MouseID, Math, x, y){
  93.     LpRatio := CalcRatio(abs(x), abs(y), Math)
  94.     Math.newX := ((x * LpRatio) * Math.biasInv) + Math.carryX, Math.newY := ((y * LpRatio) * Math.bias) + Math.carryY
  95.     Math.roundedX := round(Math.newX), Math.roundedY := round(Math.newY)
  96.     AHI.Instance.SendMouseMoveRelative(MouseID, Math.roundedX, Math.roundedY)
  97.     Math.carryX := Math.newX - Math.roundedX, Math.carryY := Math.newY - Math.roundedY
  98. }
  99.    
  100. CalcRatio(x, y, Math){
  101.     Euclid := sqrt(x**2 + y**2)
  102.     LpDist := ((Math.p > 10) ? Max(x, y) : ((Math.p <= 1) ? (x + y) : (Math.p = 2) ? Euclid : (x**Math.p + y**Math.p)**Math.pInv))
  103.     return LpDist / Euclid
  104. }
  105.  
  106.  
  107.  
Add Comment
Please, Sign In to add comment