Need Help on continuous and smooth mouse move

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
neobanana
Posts: 3
Joined: 18 Oct 2020, 12:15

Need Help on continuous and smooth mouse move

18 Oct 2020, 12:24

Hello

I am trying to make a script for Fusion 360. Basically I want to make a hotkey where if I hold the key, e.g q then it would rotate vertically as long as I hold the key

I have made the version where it would rotate everytime I press the key manually but I am stuck when I try to do it continuously

The program itself needs a shift+middle mouse to be hold before I can move the mouse

I have read the tutorial and tried

Code: Select all

q:: 
  MouseGetPos, x, y	
  Send +{Mbutton down}
  	
  while GetKeyState("q","P")
  {
  Sleep, 10	
  MouseMove,0,-5,0,R
  Send, {MButton up} 	
  MouseMove,x,y,0
  Sleep, 10
  Send, +{MButton down}
  Sleep, 10	
  }
  Send, {MButton Up} 	
  MouseMove,x,y,0	
Return
As well as

Code: Select all

q:: 
MouseGetPos, x, y	
Send +{Mbutton down}
Loop 	
{
  Sleep, 10	
  if !GetKeyState("q", "P")
    break  
  
  MouseMove,0,-5,0,R
  Sleep, 100
  Send, {MButton up}
  Sleep, 100	
  MouseMove,x,y,0
  Sleep, 10
  Send, +{MButton down}
  Sleep, 100	
}
Send, {MButton Up} 	

Return
But they both do not work. as it causes choppy movement and/or freezing of the program. Can I please get some help?

Thank you beforehand
User avatar
mikeyww
Posts: 26883
Joined: 09 Sep 2014, 18:38

Re: Need Help on continuous and smooth mouse move

18 Oct 2020, 13:06

How about this? You may need to adjust a bit, or insert other commands.

Code: Select all

q::
SoundBeep, 1500, 20
Send +{MButton Down}
KeyWait, %A_ThisHotkey% ; Wait for hotkey to be released
Send +{MButton Up}
SoundBeep, 1000, 20
Return
User avatar
Xtra
Posts: 2750
Joined: 02 Oct 2015, 12:15

Re: Need Help on continuous and smooth mouse move

18 Oct 2020, 13:17

Try:

Code: Select all

q::
MouseGetPos, x, y

while GetKeyState("q","P")
{
    Send {Shift Down}{Mbutton down}{Shift Up}
    Sleep, 50
    MouseMove,0,-5,20,R    ; Change speed parameter to smooth out movement
    Send, {MButton up}
    MouseMove,x,y,0
    Sleep, 500             ; Increase to slow / decrease to speed up
}

MouseMove,x,y,0
Return
If you still have issues can you post your original code that worked without looping.
neobanana
Posts: 3
Joined: 18 Oct 2020, 12:15

Re: Need Help on continuous and smooth mouse move

18 Oct 2020, 13:54

mikeyww wrote:
18 Oct 2020, 13:06
How about this? You may need to adjust a bit, or insert other commands.

Code: Select all

q::
SoundBeep, 1500, 20
Send +{MButton Down}
KeyWait, %A_ThisHotkey% ; Wait for hotkey to be released
Send +{MButton Up}
SoundBeep, 1000, 20
Return
well this goes well to enter the Shift+middlemouse but when I insert the move mouse command, it won't work if I hold down the button. This only works if I press,release,press again

Code: Select all

q::
SoundBeep, 1500, 20
Send +{MButton Down}
MouseMove,0,-50,0,R
Send +{MButton Up}
MouseMove,x,y
KeyWait, %A_ThisHotkey% ; Wait for hotkey to be released

SoundBeep, 1000, 20
Return

I read that https://www.reddit.com/r/AutoHotkey/comments/7c5nkq/super_new_to_ahk_trying_to_do_some_simple_camera/ might help, but I am not sure how to do it. Do you mind having a look?
neobanana
Posts: 3
Joined: 18 Oct 2020, 12:15

Re: Need Help on continuous and smooth mouse move

18 Oct 2020, 13:56

Xtra wrote:
18 Oct 2020, 13:17
Try:

Code: Select all

q::
MouseGetPos, x, y

while GetKeyState("q","P")
{
    Send {Shift Down}{Mbutton down}{Shift Up}
    Sleep, 50
    MouseMove,0,-5,20,R    ; Change speed parameter to smooth out movement
    Send, {MButton up}
    MouseMove,x,y,0
    Sleep, 500             ; Increase to slow / decrease to speed up
}

MouseMove,x,y,0
Return
If you still have issues can you post your original code that worked without looping.
I got these to work manually base on mikeyww's answer but it does not work when I hold down the button

Code: Select all

q::
SoundBeep, 1500, 20
Send +{MButton Down}
MouseMove,0,-50,0,R
Send +{MButton Up}
MouseMove,x,y
KeyWait, %A_ThisHotkey% ; Wait for hotkey to be released

SoundBeep, 1000, 20
Return
User avatar
mikeyww
Posts: 26883
Joined: 09 Sep 2014, 18:38

Re: Need Help on continuous and smooth mouse move

18 Oct 2020, 15:17

I cannot see what you are seeing and trying to do (I mean that I do not have your program), but you can try something like the following.

Code: Select all

q::
SoundBeep, 1500, 20
MouseGetPos, x, y ; Get original position
MouseMove, 0, -50,, R ; Move to button (??)
Send +{MButton Down} ; Activate
While GetKeyState(A_ThisHotkey) ; Continue while key is pressed
 Sleep, 100
Send +{MButton Up} ; Done, so release; I'm not sure whether you need the "+" here
MouseMove, x, y ; Move to original position
SoundBeep, 600, 20
Return
An alternative might be to send {Shift Down}{MButton Down} to activate, and {MButton Up}{Shift Up} to release. Actually, I think I'd try that first.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: GollyJer, Lamron750, septrinus, shawn_xwang and 245 guests