[Library] MouseDelta - See mouse input the way games see it. (Use for mouse axis->key or joystick)

Post gaming related scripts
phasermaniac
Posts: 74
Joined: 09 Apr 2017, 14:05

Re: [Library] MouseDelta - See mouse input the way games see it. (Use for mouse axis->key or joystick)

14 Apr 2017, 18:54

Do you think ahkhid can help?
https://autohotkey.com/board/topic/5357 ... -glovepie/
This guy seems that did something similar and says:
I have been successfully getting raw HID input (which must then be parsed) from my wacom cintiq with the AHKHID library

<!-- m -->http://www.autohotke... ... ght=ahkhid<!-- m -->

There are some test apps that you can use to capture your tablet's HID I/O messages. I also use BlockInput to block the tablet driver from adjusting the mouse, and use Autohotkey to handle the mouse movement instead
User avatar
evilC
Posts: 4822
Joined: 27 Feb 2014, 12:30

Re: [Library] MouseDelta - See mouse input the way games see it. (Use for mouse axis->key or joystick)

29 Apr 2017, 11:05

It would certainly be worth speaking to the interception guys, I dunno if Interception can do what you want, but they probably would.
AHKHID is going to be of no use at the moment, it uses the same technique as MouseDelta (Reading via RawInput API)
Our stumbling block is with blocking / intercepting.
bestguest

Re: [Library] MouseDelta - See mouse input the way games see it. (Use for mouse axis->key or joystick)

19 May 2017, 15:24

Hi,

Thank you for making these scripts! I want to implement your sniper-mode script but I am completely new to ahk....I was searching around for a way to change my DPI since my mouse has no driver or buttons to switch it and came accross your thread.
So I downloaded the LIBRARY, the first code in the first post and saved it as "MouseDelta.ahk" and then downloaded sniper-mode into same folder. Ran sniper-mode as administrator but when I press F12 the mouse sensitivity doesnt change.
What am I doing wrong?
If you could help out a noob in need :) I would be very grateful!
Also, how can I tweak the script to, make the mouse move faster instead of slower, at 600 DPI instead from default 400dpi while holding a button?
User avatar
masheen
Posts: 295
Joined: 06 Dec 2016, 14:10

Re: [Library] MouseDelta - See mouse input the way games see it. (Use for mouse axis->key or joystick)

18 Nov 2017, 20:51

evilC wrote:For anyone interested, I managed to implement MouseDelta as a C# DLL - see here
Can i to simulate this delta using PostMessage?
brutus_skywalker
Posts: 175
Joined: 24 Dec 2016, 13:16
Location: Antarctica

Re: [Library] MouseDelta - See mouse input the way games see it. (Use for mouse axis->key or joystick)

27 Mar 2018, 03:13

Helgef wrote: Someone asked for a mouse recorder in the ask for help section, so I tried to make a simple one.
My idea was, to save the delta info, eg, dx,dy, and then playback is simply MouseMove,dx,dy,0,R.
I realised quite quickly, that if you have any mouse acceleration or sensitivity settings on the mouse, the delta info doesn't match the mouse cursor, this is of course as (should be) expected, I felt stupid.
However, when I disabled these settings, to verify that my mouse recorder worked, in principle at least, I found that still some delta info seemed to be lost.
....
Sup dude, did you by any chance complete this mouse recorder, by all indications i'm guessing the code in that post was relating to an implementation as a UCR plugin.

I was wondering if you could post an abstraction of sorts that allows something like this, i only ask because you might have already done it, just as plugin for UCR:

Code: Select all

MouseDelta_start()   ;starts recording mouse delta to global deltaX & deltaY, concatenating all movements to one global variable pair
MouseDelta_stop()    ;stops recording, such that the movement pair recorded above can be used to replay that mouse delta movement.

MouseMove3D(){		;rough but gets the idea across, i hope.
Global
;recreate mouse delta movement, handy in games where coordinate based movement is effectively useless, this should allow moving the mouse in 3D space - i think - when paired with mouse delta data.

;move mouse single units movement, as massive jumps per deltaX 'distance' seamingly results in movement jumps that result in inconsistent movement,especially if deltaX exceeds the dimensions of the monitor.
Loop, deltaX
	{
	If A_Index = deltaX
		Break
	DllCall("mouse_event", "UInt", 0x01, "UInt", 1, "UInt", 0)
	}
Loop, deltaY
	{
	If A_Index = deltaY
		Break
	DllCall("mouse_event", "UInt", 0x01, "UInt", 0, "UInt", 1)
	}
}
Outsourcing Clicks & Presses Since 2004.
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: [Library] MouseDelta - See mouse input the way games see it. (Use for mouse axis->key or joystick)

27 Mar 2018, 04:05

Hello, maybe I have something, I do not recall, I will check later. Please send me a pm in a few days if I forget.

Cheers.
carlitototo
Posts: 1
Joined: 05 Jun 2018, 14:54

Re: [Library] MouseDelta - See mouse input the way games see it. (Use for mouse axis->key or joystick)

05 Jun 2018, 15:09

Hello Hello !
First post here, and kind of a noob to ahk, otherwise wuldn't be asking this selly question ! ! !

How do we use this librairy ?! Like, I can't figure out how to properly do something with it !

To explain the whole thing, I'm creating a bot for a game called trove to use multiple account at the same time on the same computer and reproduce the movement of the first game instance to the otherones, we got the key binded, works flawlessly, and even have an autolog, because loading 7 accounts is time consumming ( can't run more, computer can't handle it ! ). But since we need to bind the mouse movement, and this is the only option I found ( and probably the best ) How can I use it to send mouse movements to other instances ? I tried to test with the example above, but couldn't do anything, really a noob I guess ^^

Someone is up for help ?

Merci beaucoup :)

- Carlitototo
Ducky

Re: [Library] MouseDelta - See mouse input the way games see it. (Use for mouse axis->key or joystick)

11 Sep 2018, 08:27

Yeah, can we get some code that presses d when it moves to the right, and presses a for left? I am a total novice in programming too.
User avatar
evilC
Posts: 4822
Joined: 27 Feb 2014, 12:30

Re: [Library] MouseDelta - See mouse input the way games see it. (Use for mouse axis->key or joystick)

11 Sep 2018, 11:58

carlitototo wrote:Hello Hello !
First post here, and kind of a noob to ahk, otherwise wuldn't be asking this selly question ! ! !

How do we use this librairy ?! Like, I can't figure out how to properly do something with it !

To explain the whole thing, I'm creating a bot for a game called trove to use multiple account at the same time on the same computer and reproduce the movement of the first game instance to the otherones, we got the key binded, works flawlessly, and even have an autolog, because loading 7 accounts is time consumming ( can't run more, computer can't handle it ! ). But since we need to bind the mouse movement, and this is the only option I found ( and probably the best ) How can I use it to send mouse movements to other instances ? I tried to test with the example above, but couldn't do anything, really a noob I guess ^^

Someone is up for help ?

Merci beaucoup :)

- Carlitototo
This library is not for sending mouse movement, it is for responding to it
User avatar
Scr1pter
Posts: 1271
Joined: 06 Aug 2017, 08:21
Location: Germany

Re: [Library] MouseDelta - See mouse input the way games see it. (Use for mouse axis->key or joystick)

18 May 2019, 18:45

Hey guys I need your help.

I downloaded this script (which leads to this thread):

Code: Select all

#SingleInstance force
;Mausgeschwindigkeit einstellen

;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) ; ORIG
;new MouseAccelerator(0, 0.8) ; Neu
new MouseAccelerator(0, 0.7) ; Scheint am besten zu sein

; 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)
  }
  __Delete()
  {
    static RIDEV_REMOVE := 0x00000001
    static DevSize := 8 + A_PtrSize
    RAWINPUTDEVICE := this.RAWINPUTDEVICE
    NumPut(RIDEV_REMOVE, RAWINPUTDEVICE, 4, "Uint")
    DllCall("RegisterRawInputDevices", "Ptr", &RAWINPUTDEVICE, "UInt", 1, "UInt", DevSize)
  }
  ; Called when the mouse moved.
  ; Messages tend to contain small (+/- 1) movements, and happen frequently (~20ms)
  MouseMoved(wParam, lParam)
  {
      ; RawInput statics
      static DeviceSize := 2 * A_PtrSize, iSize := 0, sz := 0, offsets := {x: (20 + A_PtrSize * 2), y: (24 + A_PtrSize * 2)}, uRawInput
      static axes := {x: 1, y: 2}

      ; Find size of rawinput data - only needs to be run the first time.
      if (!iSize)
      {
        r := DllCall("GetRawInputData", "UInt", lParam, "UInt", 0x10000003, "Ptr", 0, "UInt*", iSize, "UInt", 8 + (A_PtrSize * 2))
        VarSetCapacity(uRawInput, iSize)
      }
      sz := iSize ; param gets overwritten with # of bytes output, so preserve iSize
      ; Get RawInput data
      r := DllCall("GetRawInputData", "UInt", lParam, "UInt", 0x10000003, "Ptr", &uRawInput, "UInt*", sz, "UInt", 8 + (A_PtrSize * 2))
      x := NumGet(&uRawInput, offsets.x, "Int")
      y := NumGet(&uRawInput, offsets.y, "Int")
      this.Callback.(x, y, this.Accelerationx, this.Accelerationy)

      ; There is no message for "Stopped", so simulate one
      fn := this.TimeoutFn
      SetTimer, % fn, -10
  }
  TimeoutFunc()
  {
    this.Callback.(0, 0)
  }
}
From what I understood, this script makes it impossible to work with a simple MouseMove, x, y, 0.
For this reason I tried it with DLL calls, like: DllCall("mouse_event", "UInt", 0x8001, "UInt", 19318, "UInt", 648)
With some calculation it's possible to convert the x and y positions to the absolute values.

Code: Select all

F6::
MouseGetPos, x, y ; Retrieve current mouse position
xKonvertiertMaus := x * 26 ; convert current x mouse position
yKonvertiertMaus := y * 84 / 100 ; convert current y mouse position
SetFormat Float, 0.0 ; Remove digits after comma
WinGetPos, xStart, yStart, breite, höhe, A ; Retrieve x, y, width and height
xKonvertiert := xStart * 26 ; convert xstart position of window
yKonvertiert := yStart * 84 / 100 ; convert ystart position of window
xZiel := xKonvertiertMaus + xKonvertiert ; Calculate final xMouse position
yZiel := yKonvertiertMaus + yKonvertiert ; Calculate final yMouse position
Sleep, 1000
DllCall("mouse_event", "UInt", 0x8001, "UInt", xZiel, "UInt", yZiel) ; Move mouse cursor to its original position
return
However, in some cases the mouse cursor jumps to y0.
I just made some quick calculations, but it seemed to work.

Is it perhaps possible to pause the big script, which accelerates y?
Unfortunately, it unpauses itself as soon as I move the mouse cursor.
I tried to modify it but failed.

I basically want to continue using MouseMove, x, y, 0.
How can I solve the problems?

Thanks for any help!
User avatar
evilC
Posts: 4822
Joined: 27 Feb 2014, 12:30

Re: [Library] MouseDelta - See mouse input the way games see it. (Use for mouse axis->key or joystick)

28 May 2019, 11:10

DllCall("mouse_event"... is functionally identical to DllCall("SendInput" ...

NEITHER of them can move the mouse to a specific point on the screen, both of them move the mouse by a RELATIVE amount (eg "10 units left of the current position")

Also, neither of these move the mouse in PIXELS, they move the mouse in MICKEYS
LoveStruckParadiso
Posts: 1
Joined: 03 Jun 2020, 20:47

Re: [Library] MouseDelta - See mouse input the way games see it. (Use for mouse axis->key or joystick)

03 Jun 2020, 20:52

I really need some help. Ive very confused and have no idea how to set all this up. What do i do to set up the mouse speed changer. There are three samples and I dont know what to do. Do I run them all at once?
Gavnar
Posts: 7
Joined: 22 Apr 2020, 11:52

Re: [Library] MouseDelta - See mouse input the way games see it. (Use for mouse axis->key or joystick)

27 Jun 2020, 03:46

Do you know of any script that allows for example numpad 8543 to be used as a mouse in GAMES, though uses delta input like in your example? Ive tried using regular mousemove in games which just sends the mouse all over the place. I was hoping your delta script addressed this problem but it seems to be for something else. I am very inexperienced with ahk so please forgive me if I have missed something as I dont really know much about what Im looking at.
djuga
Posts: 88
Joined: 28 Jul 2019, 08:16

Re: [Library] MouseDelta - See mouse input the way games see it. (Use for mouse axis->key or joystick)

04 Jan 2021, 14:38

Any way to detect in game mouse height ? Center, bottom, top

This works :D

Code: Select all

MouseEvent(MouseID, x := 0, y := 0){
	    Static YCheck := 0
        YCheck := YCheck < -1700 ? -1700 : YCheck > 1700 ? 1700 : YCheck - y
        Tooltip , %YCheck%
}
My questions are baffling! :crazy:
vmech
Posts: 343
Joined: 25 Aug 2019, 13:03

Re: [Library] MouseDelta - See mouse input the way games see it. (Use for mouse axis->key or joystick)

03 Feb 2021, 01:50

evilC, can you explain to me why this.Callback is polled every ~2 ms instead of 16 ms documented for Critical or any other values was manually specified ? (I tried 5-15 ms with integer incremental)

PS. I use Windows 10.0.17763 64-bit, latest AutoHotkey_L 64-bit, and A4Tech F5 mouse (with 500 Hz USB polling, which cannot be changed).
flashboy13
Posts: 1
Joined: 28 Mar 2021, 23:06

Re: [Library] MouseDelta - See mouse input the way games see it. (Use for mouse axis->key or joystick)

28 Mar 2021, 23:47

Hi! I know I'm a bit late in this thread, but I'm having a few issues as I'm really new with Ahk. I basically want to use your sample #2 but reversed. Is there a way to use delta input config that you made but instead of using the mouse to do keyboard strokes, using the keyboard to do mouse movements?
sker
Posts: 1
Joined: 28 Jul 2021, 16:09

Re: [Library] MouseDelta - See mouse input the way games see it. (Use for mouse axis->key or joystick)

28 Jul 2021, 16:24

For some reason it works fine for me only outside games (i'm talking about example 3 specifically). Once i toggle it in game and start moving mouse the whole game starts to lag like crazy (from 120 to 20-30 fps) and works fine again if the mouse remains motionless. Tried in fullscreen, windowed and borderless, all the same. Maybe the script can't keep up with 1000hz polling rate? Is there any fix for that? Because i can't find any other way\software to simulate sniper mode or change mouse speed in any way in games with rawinput...
Download Shrimp
Posts: 2
Joined: 13 Oct 2021, 19:25

Re: [Library] MouseDelta - See mouse input the way games see it. (Use for mouse axis->key or joystick)

13 Oct 2021, 19:58

I don't know if the creator of this thread is still active but:

I know I'm late to this thread, but when I run the third sample script I get a message that says:

Error at line 2.
#Include file "MouseDelta.ahk" cannot be opened.
The program will exit.

And this is the only script I could find that changes mouse DPI instead of normal mouse sensitivity.
Is there something that I need to download for MouseDelta or do I need to do something else?
I'm new to auto hotkey.

Also, the reason I'm using this script is to be able to hold down a button on my keyboard and temporarily increase mouse DPI instead of temporarily decreasing it. If you can make it easier to do that, that would be great.

Return to “Gaming Scripts (v1)”

Who is online

Users browsing this forum: No registered users and 31 guests