Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;The SendInput DllCall is specifically 32-bit. So check for the correct bitness of AutoHotkey and if not, try to run the right one.
- If (A_PtrSize=8){
- SplitPath, A_AhkPath,,Dir
- Run %Dir%\AutoHotkeyU32.exe %A_ScriptFullPath%
- ExitApp
- }
- ;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.
- ;The first is for horizontal/x-axis movement, the second for vertical/y-axis movement.
- new MouseAccelerator(0, 1)
- F12::ExitApp
- ; Gets called when mouse moves or stops
- ; x and y are DELTA moves (Amount moved since last message), NOT coordinates.
- MouseAcceleratorEvent(x := 0, y := 0, accelerationx := 2, accelerationy := 2){
- static MouseAcceleratorPaused
- If !(MouseAcceleratorPaused){
- MouseAcceleratorPaused:=true
- VarSetCapacity( MouseInput, 28, 0 )
- NumPut( x * accelerationx, MouseInput, 4, "Int" ) ; dx
- NumPut( y * accelerationy, MouseInput, 8, "Int" ) ; dy
- NumPut( 0x0001, MouseInput, 16, "UInt" ) ; MOUSEEVENTF_MOVE = 0x0001
- DllCall("SendInput", "UInt", 1, "UInt", &MouseInput, "Int", 28 )
- sleep,-1
- MouseAcceleratorPaused:=false
- }
- }
- ; ================================== LIBRARY ========================================
- ; Instantiate this class and pass it a func name or a Function Object
- ; The specified function will be called with the delta move for the X and Y axes
- ; Normally, there is no windows message "mouse stopped", so one is simulated.
- ; After 10ms of no mouse movement, the callback is called with 0 for X and Y
- ; https://autohotkey.com/boards/viewtopic.php?f=19&t=10159
- Class MouseAccelerator {
- __New(accelerationx:=2, accelerationy:=2, callback:="MouseAcceleratorEvent"){
- static DevSize := 8 + A_PtrSize
- static RIDEV_INPUTSINK := 0x00000100
- this.TimeoutFn := this.TimeoutFunc.Bind(this)
- this.Callback := callback
- this.Accelerationx := accelerationx
- this.Accelerationy := accelerationy
- ; Register mouse for WM_INPUT messages.
- VarSetCapacity(RAWINPUTDEVICE, DevSize)
- NumPut(1, RAWINPUTDEVICE, 0, "UShort")
- NumPut(2, RAWINPUTDEVICE, 2, "UShort")
- NumPut(RIDEV_INPUTSINK, RAWINPUTDEVICE, 4, "Uint")
- ; WM_INPUT needs a hwnd to route to, so get the hwnd of the AHK Gui.
- ; It doesn't matter if the GUI is showing, it still exists
- Gui +hwndhwnd
- NumPut(hwnd, RAWINPUTDEVICE, 8, "Uint")
- this.RAWINPUTDEVICE := RAWINPUTDEVICE
- DllCall("RegisterRawInputDevices", "Ptr", &RAWINPUTDEVICE, "UInt", 1, "UInt", DevSize )
- fn := this.MouseMoved.Bind(this)
- OnMessage(0x00FF, fn)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement