Negative coordinates result in weird mouse behavior

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
warspyking

Negative coordinates result in weird mouse behavior

14 Jul 2018, 19:18

I guess I'll start out with the code here...

Code: Select all

v::
DllCall("mouse_event", "UInt", 0x01, "UInt", -50, "UInt", 0)
b::
DllCall("mouse_event", "UInt", 0x01, "UInt", 50, "UInt", 0)
t::
DllCall("mouse_event", "UInt", 0x01, "UInt", 0, "UInt", -50)
g::
DllCall("mouse_event", "UInt", 0x01, "UInt", 0, "UInt", 50)
It's really short, the b and g hotkeys behave exactly as intended, but the v and t result in, well, weird behavior. They don't move the mouse at all when used multiple times in a row, if you move the mouse and then use it it'll move very slightly, but in the wrong direction, and if I spam the hotkey I can sometimes see it move in the proper direction but only for a split second before it returns. I'll be honest, I'm super confused about it.

I tried researching this issue, I found various ideas and solutions but nothing seemed to work. What ended up being most promising was using sendmode play, but that was for a previous version of the script before I was using dllcall. If you're wondering why I'm trying different approaches to the issue it's because I'm trying to write a script which, when ran in a first person game, can make me move my camera precisely and accurately in one direction without the human error possible when using the hand-controlled mouse. (So if there's another solution to this problem I'll gladly accept that instead too, I just want to solve this seemingly initially simple task.)

Who knows, maybe I'm in over my head here and this is way harder than I'm making it out to be, but either way I'm here to find out. Thanks for any help anybody has to offer, it's much appreciated!
geek
Posts: 1052
Joined: 02 Oct 2013, 22:13
Location: GeekDude
Contact:

Re: Negative coordinates result in weird mouse behavior

14 Jul 2018, 22:21

There are two ways to write a hotkey.

The first is to put a single line of code on the same line as the hotkey definition. This will run the single line of code and then stop.

The second way is to put one or more lines of code below the hotkey definition. When you do that it will keep executing lines of code going downward from the hotkey definition until it reaches a return or the end of the script file.

Your code has no returns, so when you press v it moves the mouse left then right then up then down, resulting in a net zero of movement. When you press t it moves up then down, resulting in a net zero of movement.

To fix this, either move your DllCall lines onto the same lines as the hotkey definition, or after the end of each hotkey's code put a line with the keyword return.
warspyking

Re: Negative coordinates result in weird mouse behavior

14 Jul 2018, 22:24

Ohhh. Well now I feel kinda stupid. That makes sense though, thanks. It works like a charm!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], Spawnova and 367 guests