Click down Mouse and move. Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
arbibarbarona
Posts: 63
Joined: 05 May 2021, 10:19

Re: Click down Mouse and move.

Post by arbibarbarona » 08 Jun 2022, 04:27

Code: Select all

Pos := {}
*a::
*b::
*c::
*1::
*2::
*F23::
*F24::

If GetKeyState("Ctrl") {
 MouseGetPos, x, y
 pos[A_ThisHotkey, 1] := x, pos[A_ThisHotkey, 2] := y
 SoundBeep, 1500
} Else
 MouseMove, pos[A_ThisHotkey, 1], pos[A_ThisHotkey, 2]
MouseClick, left,,, 1, 0, D
KeyWait, [A_ThisHotkey]   ; I Can't figure out how to call after keywait function
MouseClick, left,,, 1, 0, U
Return


I have this part of the script and If I'm having trouble.

I want also to send a mouse click down,,, and I don't know how to call keywait.

arbibarbarona
Posts: 63
Joined: 05 May 2021, 10:19

Re: Click down Mouse and move.

Post by arbibarbarona » 08 Jun 2022, 13:08

Got it solved.

Thanks.

Code: Select all


*a::
*b::
*c::
*1::
*2::
*F23::
*F24::
    if (GetKeyState("Ctrl")) {
        MouseGetPos, x, y
        pos[A_ThisHotkey] := [x, y]

        SoundBeep, 1500
    }
    else {
        MouseMove, pos[A_ThisHotkey, 1], pos[A_ThisHotkey, 2]
    }

    MouseClick, Left, , , 1, 0, D

    KeyWait, % RegExReplace(A_ThisHotkey, "[~*$+^! &]|AppsKey")
    MouseClick, Left, , , 1, 0, U

    return

arbibarbarona
Posts: 63
Joined: 05 May 2021, 10:19

Re: Click down Mouse and move.

Post by arbibarbarona » 10 Jun 2022, 14:27

Code: Select all

Global pos := {}, ini := StrReplace(A_ScriptFullPath, ".ahk", ".ini")
OnExit("save")
IniRead, keyNames, %ini%
For each, key in StrSplit(keyNames, "`n") {
 IniRead, section, %ini%, %key%
 For each2, line in StrSplit(section, "`n")
  part := StrSplit(line, "="), pos[key, part.1] := part.2
}


*F1::
*F2::
*F3::
*F4::


If GetKeyState("Ctrl") {
 MouseGetPos, x, y
 pos[A_ThisHotkey, 1] := x, pos[A_ThisHotkey, 2] := y
 SoundBeep, 1500
 } Else
 MouseMove, pos[A_ThisHotkey, 1], pos[A_ThisHotkey, 2]
Return


save(exitReason, exitCode) {
 For key, pair in pos
  For axis, coord in pair
   IniWrite, %coord%, %ini%, %key%, %axis%
 SoundBeep, 1000, 100
 SoundBeep, 500, 250
}
Maybe another help from you guys...
How can I add a PixelGetColor and add it in the Ini File and in the GetKeyState else if pixelcolor doesnt match mouse will not move?

Thank you in advance.

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

Re: Click down Mouse and move.

Post by mikeyww » 11 Jun 2022, 04:51

As you might guess, you can add the pixel check and If statement before your mouse move. ExampleElse

You can store whatever you like in your INI file. Example

arbibarbarona
Posts: 63
Joined: 05 May 2021, 10:19

Re: Click down Mouse and move.

Post by arbibarbarona » 01 Aug 2022, 08:12

Hello Mikeyww,

Code: Select all

	
	
	if (data1=4 and (data2=65 or data2=66 or data2=67 or data2=68 or data2=69 or data2=70 or data2=71 or data2=72) )
		{
		If !play22
		Click, D
		MouseGetPos, x, y
		Play22 := True
		MouseMove, 0, 10,, R
		SetTimer, Stop22, -600
		Return
		Stop22:
		Click, U
		MouseMove, x, y
		play22 := False
		Return
		}

	if (data1=4 and (data2=56 or data2=57 or data2=58 or data2=59 or data2=60 or data2=61 or data2=62 or data2=63) )
		{
		If !play23
		MouseGetPos, x, y
		Click, D
		Play23 := True
		MouseMove, 0, -10,, R
		SetTimer, Stop23, -600
		Return
		Stop23:
		Click, U
		MouseMove, x, y		
		play23 := False
		Return
		}
I need help with this code. I have it working if I use the HID keyboard like in the previous post. Now I was intending to use the MIDI controller Rotary for this.
My intention is MouseGetPos before the click down. then the mouse moves relatively, then after the timer lifts in 600 milliseconds, the mouse moves to the Coordinate where MouseGetPos.
I hope you can help me. Thank you so much

arbibarbarona
Posts: 63
Joined: 05 May 2021, 10:19

Re: Click down Mouse and move.

Post by arbibarbarona » 01 Aug 2022, 08:29

Code: Select all

	if (data1=3 and (data2=65 or data2=66 or data2=67 or data2=68 or data2=69 or data2=70 or data2=71 or data2=72) )
		{
		If !play20
		SendEvent, {LButton down}
		Play20 := True
		MouseMove, 15, 0,, R
		Sleep, 50
		SetTimer, Stop20, -200
		Return
		Stop20:
		SendEvent, {LButton up}
		MouseMove, -15, 0,,R
		play20 := False
		Return
		}

	if (data1=3 and (data2=56 or data2=57 or data2=58 or data2=59 or data2=60 or data2=61 or data2=62 or data2=63) )
		{
		If !play21
		SendEvent, {LButton down}
		Play21 := True
		MouseMove, -15, 0,, R
		Sleep, 50
		SetTimer, Stop21, -200
		Return
		Stop21:
		SendEvent, {LButton up}
		MouseMove, 15, 0,,R
		play21 := False
		Return
		}
this does work sometimes but I got hiccups at times if I move the Midi Knob faster. It doesn't recognizes the LButton Up event.
There might be an efficient way than in my code.

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

Re: Click down Mouse and move.

Post by mikeyww » 01 Aug 2022, 08:52

You might want to test with a simpler script. This worked (I have no such knob).

Aside from the timer here, there is no looping. If you need looping and checking a condition (e.g., idle mouse or keyboard), you would add that.

By default, coordinates are relative to the active window. If the active window changes, then the command will use whichever window is active when the command executes.

Code: Select all

#Persistent
SoundBeep, 1500
Sleep, 1500

If !play22
 SoundBeep, 1200
MouseGetPos, x, y
play22 := True
MouseMove, 0, 10,, R
SetTimer, Stop22, -1000
Return

Stop22:
play22 := False
MouseMove, x, y
SoundBeep, 900
Return

arbibarbarona
Posts: 63
Joined: 05 May 2021, 10:19

Re: Click down Mouse and move.

Post by arbibarbarona » 06 Aug 2022, 09:39

Hi Mikeyww,
I dont want to hack other thread since this is related to my post I will follow here.

Can I ask for help on setting logic to this ACC Library script that I have? I want to set a logic that if the Object path isn't detected the action will break. here's the script

Code: Select all

#INCLUDE %A_ScriptDir%\Anchor.ahk
#INCLUDE %A_ScriptDir%\Acc.ahk

#IfWinActive ahk_exe Resolve.exe

^a::

WinGet, hWnd, ID, A
oAcc := Acc_Get("Object", "4.2.2.1.1.2.3.2.1.1.1.1.1.1.1.2.1.1.2.1.3.2", 0, "ahk_id " hWnd)
oRect := Acc_Location(oAcc)
CoordMode, Mouse, Screen
vCurX := oRect.x + oRect.w/2
vCurY := oRect.y + oRect.h/2
oAcc := oRect := ""
MouseMove, % vCurX, % vCurY
return

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

Re: Click down Mouse and move.

Post by mikeyww » 06 Aug 2022, 09:47

Perhaps:

Code: Select all

If !IsObject(oAcc)
 Return
Or:

Code: Select all

If !oAcc
 Return

arbibarbarona
Posts: 63
Joined: 05 May 2021, 10:19

Re: Click down Mouse and move.

Post by arbibarbarona » 06 Aug 2022, 10:23

Code: Select all

	if (chan=1 and data1=0 and data2=127 ) ;Temperature
		{
		If !IsObject(oAcc)=True

		WinGet, hWnd, ID, A
		oAcc := Acc_Get("Object", "4.2.2.1.1.2.3.2.1.1.1.1.1.1.1.2.1.1.1.1.2.1.2", 0, "ahk_id " hWnd)
		oRect := Acc_Location(oAcc)
		CoordMode, Mouse, Screen
		vCurX := oRect.x + oRect.w/2
		vCurY := oRect.y + oRect.h/2
		oAcc := oRect := ""
		SystemCursor(False)
		MouseMove, % vCurX, % vCurY
		SystemCursor(True)
		return

		If !IsObject(oAcc)=False
		Return
		}
This doesn't seem to work.

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

Re: Click down Mouse and move.

Post by mikeyww » 06 Aug 2022, 10:37

Could try:

Code: Select all

^a::
If oAcc := Acc_Get("Object", "4.2.2.1.1.2.3.2.1.1.1.1.1.1.1.2.1.1.2.1.3.2", 0, "ahk_id" WinActive("A")) {
 oRect := Acc_Location(oAcc)
 CoordMode, Mouse
 MouseMove, oRect.x + oRect.w / 2, oRect.y + oRect.h / 2
} Else SoundBeep, 1000
Return
Last edited by mikeyww on 06 Aug 2022, 10:45, edited 1 time in total.

arbibarbarona
Posts: 63
Joined: 05 May 2021, 10:19

Re: Click down Mouse and move.

Post by arbibarbarona » 06 Aug 2022, 10:45

Thanks Mikeyww, Its working now.

arbibarbarona
Posts: 63
Joined: 05 May 2021, 10:19

Re: Click down Mouse and move.

Post by arbibarbarona » 09 Aug 2022, 09:01

It's me again Mikeyww.

How to add to the script that the mouse move to oRect.x + oRect.w / 2, oRect.y + oRect.h / 2 only acts once when called . and since the mouse is in the oRec.x oRec.y area it doesnt call that mouse move function after it loops. the only move action is in If !Play loop? or my Script need tydying?

Thank you.


Code: Select all

    if (chan=16 and data1=20 and data2=65 ) ;CW
		{

		If oAcc := Acc_Get("Object", "4.2.2.1.1.2.3.2.1.1.1.1.1.1.1.2.1.1.1.1.2.1.2", 0, "ahk_id" WinActive("A"))
		{
			oRect := Acc_Location(oAcc)
			CoordMode, Mouse
			MouseMove, oRect.x + oRect.w / 2, oRect.y + oRect.h / 2
			loop
			{
			If !play20
			play20 := True
			SendEvent, {LButton down}
			MouseMove, 15, 0,, R
			SetTimer, Stop20, -500
			return

			Stop20:
			play20 := False
			SendEvent, {LButton up}
			sleep, 50
			return
			}
		}

		Else SoundBeep, 500
		oAcc := oRect := ""
		Return
        }

	if (chan=16 and data1=20 and data2=63 ) ;CCW
		{

		If oAcc := Acc_Get("Object", "4.2.2.1.1.2.3.2.1.1.1.1.1.1.1.2.1.1.1.1.2.1.2", 0, "ahk_id" WinActive("A"))
		{
			oRect := Acc_Location(oAcc)
			CoordMode, Mouse
			MouseMove, oRect.x + oRect.w / 2, oRect.y + oRect.h / 2
			loop
			{
			If !play21
			play21 := True
			SendEvent, {LButton down}
			MouseMove, -15, 0,, R
			SetTimer, Stop21, -500
			return

			Stop21:
			play21 := False
			SendEvent, {LButton up}
			sleep, 50
			return
			}
		}

		Else SoundBeep, 500
		oAcc := oRect := ""
		Return
        }
        

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

Re: Click down Mouse and move.

Post by mikeyww » 09 Aug 2022, 09:14

I do not know your goal, but the flow looks problematic. You have an infinite loop that keeps resetting a timer forever. You might want to do some debugging here: follow the script line by line; see what it is doing, line by line. Timers are rarely needed inside loops. If you need a new mouse move inside your loop, you can put one there. If you need a sleep instead of a timer, or a timer instead of a loop, then you can make that change.

You can consider removing the second conditional block, and removing the Loop command, while you test a single iteration, so that you can get one iteration working properly.

arbibarbarona
Posts: 63
Joined: 05 May 2021, 10:19

Re: Click down Mouse and move.

Post by arbibarbarona » 09 Aug 2022, 11:27

The goal is to merge these two scripts. the goal is to use ACC Library to locate the Object path and hover the mouse in the center of the object. Then have that mouse position CLick down. While the mouse left is down, move the mouse horizontal left or right with the MIDI CC encoder. when no movement is detected within 300ms, the mouse clicks up. It's like how the Knobs of a Davinci Color panel behave. Instead of a hotkey, I use a MIDI controller here.

But MIDI Command isnt like Hotkey.

Clockwise Rotation is ie... (chan=11 and data1=20 and data2=65)
Counterclockwise rotation is (chan=11 and data1=20 and data2=63)


Code: Select all

{
		If oAcc := Acc_Get("Object", "", 0, "ahk_id" WinActive("A")) {
		oRect := Acc_Location(oAcc)
		CoordMode, Mouse
		MouseMove, oRect.x + oRect.w / 2, oRect.y + oRect.h / 2

		} Else SoundBeep, 500
		oAcc := oRect := ""
		Return
		}

Code: Select all

}

If !go
 Click, D
go := True
MouseMove, 0, A_ThisHotkey = "^Up" ? 5 : -5,, R
SetTimer, Stop2, -200
Return
Stop2:
Click, U
go := False
Return]

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

Re: Click down Mouse and move.

Post by mikeyww » 09 Aug 2022, 11:48

Which line detects no movement within 300 ms? Are you referring to the user's manual mouse moves? If so, how is that being done? If not, then what sort of detection is occurring?

arbibarbarona
Posts: 63
Joined: 05 May 2021, 10:19

Re: Click down Mouse and move.

Post by arbibarbarona » 09 Aug 2022, 12:38

Code: Select all

    if (chan=16 and data1=20 and data2=65 ) ;CW
		{
			If !play20
			play20 := True
			If oAcc := Acc_Get("Object", "4.2.2.1.1.2.3.2.1.1.1.1.1.1.1.2.1.1.1.1.2.1.2", 0, "ahk_id" WinActive("A")){
			oRect := Acc_Location(oAcc)
			CoordMode, Mouse
			MouseClick, L, oRect.x + oRect.w / 2, oRect.y + oRect.h / 2, , , D
			MouseMove, 15, 0,, R
			SetTimer, Stop20, -300
			return

			Stop20:
			play20 := False
			Click, U
			return

		}

		Else SoundBeep, 500
		oAcc := oRect := ""
		Return
        }

	if (chan=16 and data1=20 and data2=63 ) ;CCW
		{

			If !play21
			play21 := True
			If oAcc := Acc_Get("Object", "4.2.2.1.1.2.3.2.1.1.1.1.1.1.1.2.1.1.1.1.2.1.2", 0, "ahk_id" WinActive("A")){
			oRect := Acc_Location(oAcc)
			CoordMode, Mouse
			MouseClick, L, oRect.x + oRect.w / 2, oRect.y + oRect.h / 2, , , D
			MouseMove, -15, 0,, R
			SetTimer, Stop21, -300
			return

			Stop21:
			play21 := False
			Click, U
			return

		}

		Else SoundBeep, 500
		oAcc := oRect := ""
		Return
        }
This seems to work but is a bit buggy. I don't know how to clean this up or have it more efficient.

arbibarbarona
Posts: 63
Joined: 05 May 2021, 10:19

Re: Click down Mouse and move.

Post by arbibarbarona » 19 Aug 2022, 10:33

Code: Select all

	if (chan=1 and data1=1 and (data2=65 or data2=66 or data2=67 or data2=68 or data2=69 or data2=70 or data2=71 or data2=72) )
		{

			If oAcc := Acc_Get("Object", "4.2.2.1.1.2.3.2.1.1.1.1.1.1.1.2.1.1.2.2.2", 0, "ahk_id" WinActive("A")){
			oRect := Acc_Location(oAcc)

			If !play20
			MouseClick, L, oRect.x + oRect.w / 2, oRect.y + oRect.h / 2, , , D
			play20 := True
			MouseMove, 15, 0,, R
			SetTimer, Stop40, -500
			return

			Stop40:

			MouseClick, L, , , , , U
			play20 := False
			return

		}

		Else SoundBeep, 500
		oAcc := oRect := ""
		Return
        }


	if (chan=1 and data1=1 and (data2=56 or data2=57 or data2=58 or data2=59 or data2=60 or data2=61 or data2=62 or data2=63) )
		{

			If oAcc := Acc_Get("Object", "4.2.2.1.1.2.3.2.1.1.1.1.1.1.1.2.1.1.2.2.2", 0, "ahk_id" WinActive("A")){
			oRect := Acc_Location(oAcc)

			If !play21
			MouseClick, L, oRect.x + oRect.w / 2, oRect.y + oRect.h / 2, , , D
			play21 := True
			MouseMove, -15, 0,, R
			SetTimer, Stop41, -500
			return

			Stop41:
			MouseClick, L, , , , , U
			play21 := False
			return

		}

		Else SoundBeep, 500
		oAcc := oRect := ""
		Return
        }
Hi Mikeyww. The code above is a little buggy. I don't know how to troubleshoot. Any help? Thank you so much.

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

Re: Click down Mouse and move.

Post by mikeyww » 19 Aug 2022, 12:12

Since I do not know what "buggy" means or what happens when you run the script, I will suggest troubleshooting strategies.

1. Eliminate the second large If block, so that you can troubleshoot only the first block until it works properly.
2. Display values of key variables, such as play20, so that you know what these values are, when they are defined or assessed.
3. Add other visual cues (tooltip, MsgBox, etc.), so that you know which sections (e.g., Stop40) are executing, and when.
4. Use some of the AHK tools such as KeyHistory or ListLines, so that you know what is being clicked, sent, etc.
5. Fix your indentation so that it uses a sensible and consistent approach. It currently generates confusion, and you might be missing some block definitions where you believe that you currently have them. For example, some of your If blocks are indented, while others are not. Some of your braces are indented, while others are outdented. From my perspective, this is not only hard to follow, but might be increasing the chance that you introduce a bug into your coding.

arbibarbarona
Posts: 63
Joined: 05 May 2021, 10:19

Re: Click down Mouse and move.

Post by arbibarbarona » 21 Aug 2022, 13:39

Code: Select all

	if (chan=1 and data1=1 and (data2=65 or data2=66 or data2=67 or data2=68 or data2=69 or data2=70 or data2=71 or data2=72) )
		{

		If oAcc := Acc_Get("Object", "4.2.2.1.1.2.3.2.1.1.1.1.1.1.1.2.1.1.1.1.2.1.2", 0, "ahk_id" WinActive("A"))
				{
				oRect := Acc_Location(oAcc)
				CoordMode, Mouse
				MouseClick, L, oRect.x + oRect.w / 2, oRect.y + oRect.h / 2, , , D

				play20 := True
				MouseMove, 25, 0,, R
				SetTimer, Stop40, -800
				Stop40:
				play20 := False
				MouseClick, L, , , , , U
				return
				}

			Else SoundBeep, 500
			oAcc := oRect := ""
			Return
        }


	if (chan=1 and data1=1 and (data2=56 or data2=57 or data2=58 or data2=59 or data2=60 or data2=61 or data2=62 or data2=63) )
		{

			If oAcc := Acc_Get("Object", "4.2.2.1.1.2.3.2.1.1.1.1.1.1.1.2.1.1.1.1.2.1.2", 0, "ahk_id" WinActive("A"))
				{
				oRect := Acc_Location(oAcc)
				CoordMode, Mouse
				MouseClick, L, oRect.x + oRect.w / 2, oRect.y + oRect.h / 2, , , D

				play21 := True
				MouseMove, -25, 0,, R
				SetTimer, Stop41, -800
				Stop41:
				play21 := False
				MouseClick, L, , , , , U
				return
				}

			Else SoundBeep, 500
			oAcc := oRect := ""
			Return
        }
This seems to work but mouse move seems slow and Settimer doesn't seem to function. Is there a way the mouse move is either incremental and or decremental instead of relative pixel?

Post Reply

Return to “Ask for Help (v1)”