Sign in to follow this  
Followers 0
Traddles

numPad Mouse Weird Error

13 posts in this topic

Ok, so I'm lazy and decided to make a little script to make it easier to use the mouse when I only have physical access to my keyboard. I've attached the script.

Basically the script works like this. When you run it it will start an infinite loop that will check if any of the numPad keys are down, if they are it will move the mouse in that direction according to a speed variable. Whenever the 5 key is pressed in that speed variable is divided by a scaling factor and whenever the 5 key is released the speed variable is multiplied by that scaling factor. So, the weirdness happens when I'm holding in the 5 key and move the mouse to the left (by pressing in the 4 key). Seems to be normal, but then notice how quickly the mouse moves when you hold in the 5 key and move the mouse to the right (the 6 key). Why is one faster? The same code governs both mouse movements?

The same is true of up and down as well. In fact, to really demonstrate the weirdness, hold in five and hold the 1 key for a bit and see the path that the mouse takes. Then look at the code that is supposed to be governing this movement.

Any ideas about this?

P.S. Sorry it's a CPU hog.

numMouse.au3

Share this post


Link to post
Share on other sites



oh, also for a quick, easy kill of the script press the numpad divide key.

Share this post


Link to post
Share on other sites

nobody has any ideas?

Share this post


Link to post
Share on other sites

still no one has any ideas?

...

bump

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

This is kind of a half answer I hope you don't mind... I have a headache and can't think entirely straight... The problem had to do with your math on $speed. I cleaned up your code some, but commenting/uncommenting lines under your ispressed function for 5 you'll see what I mean.

As I said, I cleaned up your code generally, everything still works the same, but I think it makes for a much easier source to read. Also, I added a sleep(10) to your loop to bring the CPU usuage down by a lot. Just note that adding that sleep effects your script in general, hard to explain but comment/uncomment it and it will be obvious. Leaving it in though, everything that it affects it affects uniformly, and really brings down the CPU. Ultimately your problem is fixed, if I can give you a decent explanation I will, but alas headache is to scripting, as paper is to rock... it wins everytime. :D

EDIT: I decided it was time to use the dog laughing for that terrible joke

numMouse.au3

Edited by someone

While ProcessExists('Andrews bad day.exe')
	BlockInput(1)
	SoundPlay('Music.wav')
	SoundSetWaveVolume('Louder')
WEnd

Share this post


Link to post
Share on other sites

Very nice. I was gonna make a script like this cause I'm tired of my wireless mouse batteries dying all the time. I updated a couple lines to prevent negative movement.

Func speedUp()
    If $speed < 100 Then $speed += 1
EndFunc

Func speedDown()
    If $speed > 1 Then $speed -= 1
EndFunc

Share this post


Link to post
Share on other sites

Good call, I missed that


While ProcessExists('Andrews bad day.exe')
	BlockInput(1)
	SoundPlay('Music.wav')
	SoundSetWaveVolume('Louder')
WEnd

Share this post


Link to post
Share on other sites

I was having some weirdness with the mouse clicks. I changed the code so it doesn't just click like crazy when the 0 or . keys are pressed.

mousepad.au3

Share this post


Link to post
Share on other sites

Very nice, folks. I was wondering if there is an AutoIt counterpart for the Autohotkey script NumpadMouse I'm using for a long while but ain't totally satisfied with it. Yes, there is.

I'd encourage you to enhance it. My Autoit knowledge is enough only to change the keys (I've set key 5 as left click and key 0 as right click, just like in my AHK script version), but there would be a lot of ways to improve it:

drag and drop (a big problem with the AHK version that it can't do a drag and drop, so I have to keep the built in Windows keyboard mouse at hand, too);

mouse wheel movement;

a switch to turn it on/off;

a config panel to set which key to perform which function.

These could make it a full-fledged utility!

Láng Attila D., http://lattilad.org


Láng Attila D., LAttilaD.org

Share this post


Link to post
Share on other sites

Welcome to the forum. I fixed the mouse drag and drop issue... my original upload didn't work correctly which spudw2k fixed but by removing drag and drop. Other then that a switch to turn it on and off is the exact same thing as pausing a script; theres a great example for that under hotkeyset in the help file.

For mouse wheel movement, check out MouseWheel().

The config panel is the hardest part because it requires you to make a GUI, but this is as good a time to learn as any.

I encourage YOU to enhance it :)

numMouse.au3


While ProcessExists('Andrews bad day.exe')
	BlockInput(1)
	SoundPlay('Music.wav')
	SoundSetWaveVolume('Louder')
WEnd

Share this post


Link to post
Share on other sites

Thank you, someone. Meanwhile, I found another script here and modified it. My version is following below. It drags and drops and moves the wheel.

It's strange that your version moves the pointer much smoother than the other one. I prefer smoother movement. I believe I'm going to study your version more.

Láng Attila D., http://lattilad.org

#include <Misc.au3>
Opt("TrayAutoPause",0)
HotKeySet("{NUMPAD5}", "mleftbutton")
HotKeySet("{NUMPAD0}", "mrightbutton")

HotKeySet("{NUMPAD2}", "mdown")
HotKeySet("{NUMPAD4}", "mleft")
HotKeySet("{NUMPAD6}", "mright")
HotKeySet("{NUMPAD8}", "mup")

HotKeySet("{NUMPAD1}", "mleftdown")
HotKeySet("{NUMPAD3}", "mrightdown")
HotKeySet("{NUMPAD7}", "mleftup")
HotKeySet("{NUMPAD9}", "mrightup")

HotKeySet("{NUMPADADD}", "wheeldown")
HotKeySet("{NUMPADSUB}", "wheelup")

HotKeySet("{NUMPADDIV}", "quit")
$speed = 5
$pos = MouseGetPos()

While 1
    Sleep(100)
Wend

Func mleftbutton()
    HotKeySet("{NUMPAD5}")
    MouseDown("left")
    While _IsPressed(65)
        Sleep(100)
    WEnd
    MouseUp("left")
    HotKeySet("{NUMPAD5}", "mleftbutton")
EndFunc

Func mrightbutton()
    HotKeySet("{NUMPAD0}")
    MouseDown("right")
    While _IsPressed(60)
        Sleep(100)
    WEnd
    MouseUp("right")
    HotKeySet("{NUMPAD0}", "mrightbutton")
EndFunc

Func mdown()
$pos[1]=$pos[1] + $speed
move()
EndFunc

Func mleft()
$pos[0]=$pos[0] - $speed
move()
EndFunc

Func mright()
$pos[0]=$pos[0] + $speed
move()
EndFunc

Func mup()
$pos[1]=$pos[1] - $speed
move()
EndFunc

func mleftdown()
$pos[0]=$pos[0] - $speed
$pos[1]=$pos[1] + $speed
move()
endfunc

func mrightdown()
$pos[0]=$pos[0] + $speed
$pos[1]=$pos[1] + $speed
move()
endfunc

func mleftup()
$pos[0]=$pos[0] - $speed
$pos[1]=$pos[1] - $speed
move()
endfunc

func mrightup()
$pos[0]=$pos[0] + $speed
$pos[1]=$pos[1] - $speed
move()
endfunc

func move()
MouseMove($pos[0], $pos[1], 1)
endfunc

func wheelup()
mousewheel("up", 1)
endfunc

func wheeldown()
mousewheel("down", 1)
endfunc

Func quit()
    HotKeySet("{NUMPAD0}")
    HotKeySet("{NUMPAD1}")
    HotKeySet("{NUMPAD2}")
    HotKeySet("{NUMPAD3}")
    HotKeySet("{NUMPAD4}")
    HotKeySet("{NUMPAD5}")
    HotKeySet("{NUMPAD6}")
    HotKeySet("{NUMPAD7}")
    HotKeySet("{NUMPAD8}")
    HotKeySet("{NUMPAD9}")
    HotKeySet("{NUMPADDOT}")
    HotKeySet("{NUMPADADD}")
    HotKeySet("{NUMPADSUB}")
    HotKeySet("{NUMPADDIV}")
    Exit
EndFunc

Láng Attila D., LAttilaD.org

Share this post


Link to post
Share on other sites

Pretty sure what is causing the jumpiness is your large sleep() commands in your While loops. Even if you take the script I uploaded and changed the sleep from 10 to 100 you'll see jumpiness.

Autoit is a single threaded language, meaning it only ever does onething at a time. So every so often it encounters a small sleep and does that instead of move the mouse. Its hardly noticeable, and the alternative would be to remove the sleep, and play around with the speed of MouseMove (if you don't know what I mean check the help file). If you do that though the CPU usuage will get very high. Bottom line is I really don't think its worth it, just leave the small sleep in.


While ProcessExists('Andrews bad day.exe')
	BlockInput(1)
	SoundPlay('Music.wav')
	SoundSetWaveVolume('Louder')
WEnd

Share this post


Link to post
Share on other sites

Pretty sure what is causing the jumpiness is your large sleep() commands in your While loops. Even if you take the script I uploaded and changed the sleep from 10 to 100 you'll see jumpiness.

Now I've changed all sleeps to 1 in the other version and it isn't so smooth as yours. So I'll insist on yours. :)


Láng Attila D., LAttilaD.org

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0