Adjusting the speed on keys for mouse movement

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
minesparky72
Posts: 9
Joined: 24 Aug 2021, 21:59

Adjusting the speed on keys for mouse movement

Post by minesparky72 » 06 Dec 2021, 19:19

I am just learning AHK. Thanks for everyones help!!! I am having fun with AHK. I am trying to make the mouse move with Key strokes. I copied the code from the AHK site. Everything works but the speed is a bit slow. I add the code in the script that the site says to speed the mouse movement but is doesn't do anything. The mouse moves the same speed. Can someone help? Not sure if this is how i show my code but this is what i got so far

Code: Select all

*#up::MouseMove, 0, -10, 0, R  ; Win+UpArrow hotkey => Move cursor upward
*#Down::MouseMove, 0, 10, 0, R  ; Win+DownArrow => Move cursor downward
*#Left::MouseMove, -10, 0, 0, R  ; Win+LeftArrow => Move cursor to the left
*#Right::MouseMove, 10, 0, 0, R  ; Win+RightArrow => Move cursor to the right

*<#RCtrl::  ; LeftWin + RightControl => Left-click (hold down Control/Shift to Control-Click or Shift-Click).
SendEvent {Blind}{LButton down}
KeyWait RCtrl  ; Prevents keyboard auto-repeat from repeating the mouse click.
SendEvent {Blind}{LButton up}
return

*<#AppsKey::  ; LeftWin + AppsKey => Right-click
SendEvent {Blind}{RButton down}
KeyWait AppsKey  ; Prevents keyboard auto-repeat from repeating the mouse click.
SendEvent {Blind}{RButton up}
return
[Mod edit: [code][/code] tags added.]
Last edited by gregster on 06 Dec 2021, 21:30, edited 1 time in total.
Reason: Topic moved from 'Scripts and Functions'.

User avatar
Xtra
Posts: 2744
Joined: 02 Oct 2015, 12:15

Re: Adjusting the speed on keys for mouse movement

Post by Xtra » 07 Dec 2021, 00:08

You can try putting this at the top of your script:

Code: Select all

SetDefaultMouseSpeed, 0
or

Code: Select all

SendMode, Input
Click the text in the code box to bring up the AHK help file.

minesparky72
Posts: 9
Joined: 24 Aug 2021, 21:59

Re: Adjusting the speed on keys for mouse movement

Post by minesparky72 » 07 Dec 2021, 14:03

Ok. I thought i tried that but not sure if I had it at the top of script. This is just a small part of my script. Does this have to be a the top or just at the top of the code for the mouse movement?

User avatar
Xtra
Posts: 2744
Joined: 02 Oct 2015, 12:15

Re: Adjusting the speed on keys for mouse movement

Post by Xtra » 07 Dec 2021, 14:52

Top of the script will make it the default for the whole script unless specified differently elsewhere. (per thread basis)
See: auto-executesection

User avatar
boiler
Posts: 16772
Joined: 21 Dec 2014, 02:44

Re: Adjusting the speed on keys for mouse movement

Post by boiler » 08 Dec 2021, 02:44

Also, if you don’t put it at the top of the script and appears below (but not part of) your hotkey routines, then it is never executed if the flow of the script is never directed to it, such as part of a labeled subroutine that gets called.

minesparky72
Posts: 9
Joined: 24 Aug 2021, 21:59

Re: Adjusting the speed on keys for mouse movement

Post by minesparky72 » 12 Dec 2021, 11:41

So i tryed that and it seems to be going the same speed. i was thinking that the other code might be affecting it so i made another script and just put this code in.
The speed is the same no matter what number i put in.

Code: Select all

SetDefaultMouseSpeed, 0
=:: MouseMove, 0, -10, 0, R  ; equal hotkey => Move cursor upward
numpad8:: MouseMove, 0, 10, 0, R  ; numpad 8 => Move cursor downward
numpad7:: MouseMove, -10, 0, 0, R  ; numpad 7 => Move cursor to the left
numpad9:: MouseMove, 10, 0, 0, R  ; numpad 9 => Move cursor to the right
backspace::  ; BackSpace => Left-click (hold down Control/Shift to Control-Click or Shift-Click).
SendEvent {Blind}{LButton down}
KeyWait RCtrl  ; Prevents keyboard auto-repeat from repeating the mouse click.
SendEvent {Blind}{LButton up}
return
[Mod edit: [code][/code] tags added.]

User avatar
mikeyww
Posts: 26601
Joined: 09 Sep 2014, 18:38

Re: Adjusting the speed on keys for mouse movement

Post by mikeyww » 12 Dec 2021, 12:18

Code: Select all

#Up::
While GetKeyState("Up", "P") & GetKeyState("LWin", "P") {
 DllCall("mouse_event", "UInt", RELMOVE := 1, "UInt", X := 0, "UInt", Y := -10)
 Sleep, 10
}
Return

minesparky72
Posts: 9
Joined: 24 Aug 2021, 21:59

Re: Adjusting the speed on keys for mouse movement

Post by minesparky72 » 12 Dec 2021, 12:38

I'm sorry. I don't know what your saying here.

User avatar
mikeyww
Posts: 26601
Joined: 09 Sep 2014, 18:38

Re: Adjusting the speed on keys for mouse movement

Post by mikeyww » 12 Dec 2021, 13:08

If you try the script and press Win+Up, you can see whether the mouse moves more quickly.

minesparky72
Posts: 9
Joined: 24 Aug 2021, 21:59

Re: Adjusting the speed on keys for mouse movement

Post by minesparky72 » 12 Dec 2021, 15:35

It’s faster!!!!! I’ll try changing this to the keys I need to move the mouse. What is the number I change to adjust to the speed I need ?

User avatar
mikeyww
Posts: 26601
Joined: 09 Sep 2014, 18:38

Re: Adjusting the speed on keys for mouse movement

Post by mikeyww » 12 Dec 2021, 16:43

The number is 10 in the Sleep statement.

Post Reply

Return to “Ask for Help (v1)”