Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2017
822
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.72 KB | None | 0 0
  1. ;The SendInput DllCall is specifically 32-bit. So check for the correct bitness of AutoHotkey and if not, try to run the right one.
  2. If (A_PtrSize=8){
  3. SplitPath, A_AhkPath,,Dir
  4. Run %Dir%\AutoHotkeyU32.exe %A_ScriptFullPath%
  5. ExitApp
  6. }
  7.  
  8. ;Call below to accelerate the mouse input. The first two parameters are the integer factors of artificial amplification added on top of the physical input.
  9. ;The first is for horizontal/x-axis movement, the second for vertical/y-axis movement.
  10. new MouseAccelerator(0, 1)
  11.  
  12. F12::ExitApp
  13.  
  14.  
  15. ; Gets called when mouse moves or stops
  16. ; x and y are DELTA moves (Amount moved since last message), NOT coordinates.
  17. MouseAcceleratorEvent(x := 0, y := 0, accelerationx := 2, accelerationy := 2){
  18. static MouseAcceleratorPaused
  19. If !(MouseAcceleratorPaused){
  20. MouseAcceleratorPaused:=true
  21. VarSetCapacity( MouseInput, 28, 0 )
  22. NumPut( x * accelerationx, MouseInput, 4, "Int" ) ; dx
  23. NumPut( y * accelerationy, MouseInput, 8, "Int" ) ; dy
  24. NumPut( 0x0001, MouseInput, 16, "UInt" ) ; MOUSEEVENTF_MOVE = 0x0001
  25. DllCall("SendInput", "UInt", 1, "UInt", &MouseInput, "Int", 28 )
  26. sleep,-1
  27. MouseAcceleratorPaused:=false
  28. }
  29. }
  30.  
  31. ; ================================== LIBRARY ========================================
  32. ; Instantiate this class and pass it a func name or a Function Object
  33. ; The specified function will be called with the delta move for the X and Y axes
  34. ; Normally, there is no windows message "mouse stopped", so one is simulated.
  35. ; After 10ms of no mouse movement, the callback is called with 0 for X and Y
  36. ; https://autohotkey.com/boards/viewtopic.php?f=19&t=10159
  37. Class MouseAccelerator {
  38. __New(accelerationx:=2, accelerationy:=2, callback:="MouseAcceleratorEvent"){
  39. static DevSize := 8 + A_PtrSize
  40. static RIDEV_INPUTSINK := 0x00000100
  41.  
  42. this.TimeoutFn := this.TimeoutFunc.Bind(this)
  43.  
  44. this.Callback := callback
  45. this.Accelerationx := accelerationx
  46. this.Accelerationy := accelerationy
  47. ; Register mouse for WM_INPUT messages.
  48. VarSetCapacity(RAWINPUTDEVICE, DevSize)
  49. NumPut(1, RAWINPUTDEVICE, 0, "UShort")
  50. NumPut(2, RAWINPUTDEVICE, 2, "UShort")
  51. NumPut(RIDEV_INPUTSINK, RAWINPUTDEVICE, 4, "Uint")
  52. ; WM_INPUT needs a hwnd to route to, so get the hwnd of the AHK Gui.
  53. ; It doesn't matter if the GUI is showing, it still exists
  54. Gui +hwndhwnd
  55. NumPut(hwnd, RAWINPUTDEVICE, 8, "Uint")
  56.  
  57. this.RAWINPUTDEVICE := RAWINPUTDEVICE
  58. DllCall("RegisterRawInputDevices", "Ptr", &RAWINPUTDEVICE, "UInt", 1, "UInt", DevSize )
  59. fn := this.MouseMoved.Bind(this)
  60. OnMessage(0x00FF, fn)
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement