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.

09 May 2021, 12:01

Thank you so much for this. This is perfect for what I need.

Code: Select all

F21::
F22::
If !go
 Click, 134 739 D
go := True
MouseMove, A_ThisHotkey = "F21" ? -3 : 3, 0,, R
SetTimer, Stop, -300
Return
Stop:
Click, U
go := False
Return
[Mod edit: [code][/code] tags added.]
Last edited by gregster on 09 May 2021, 12:03, edited 1 time in total.
Reason: [code] tags added, again. Please use them yourself, next time. Thank you!
gregster
Posts: 8999
Joined: 30 Sep 2013, 06:48

Re: Click down Mouse and move.

09 May 2021, 12:09

@arbibarbarona : Do you have a question on how to use code tags ?
([code]code goes here[/code] )

If so, feel free to ask! (You can also do this via PM - there is still one waiting that I sent to you which you didn't read yet.)
If not, it would be appreciated if you started using them. Thank you!
arbibarbarona
Posts: 63
Joined: 05 May 2021, 10:19

Re: Click down Mouse and move.

09 May 2021, 12:13

gregster wrote:
09 May 2021, 12:09
@arbibarbarona : Do you have a question on how to use code tags ?
([code]code goes here[/code] )

If so, feel free to ask! (You can also do this via PM - there is still one waiting that I sent to you which you didn't read yet.)
If not, it would be appreciated if you started using them. Thank you!
Noted on these. Thank you.
arbibarbarona
Posts: 63
Joined: 05 May 2021, 10:19

Re: Click down Mouse and move.

09 May 2021, 23:00

While this code works in horizontal mouse movement

Code: Select all

F13::
F14::
If !go
 Click, D
go := True
MouseMove, A_ThisHotkey = "F13" ? -2:2, 0,, R
SetTimer, Stop, -400
Return
Stop:
Click, U
go := False
Return

I can't make it work in the Vertical mouse move.

Code: Select all

+F13::
+F14::
If !go
 Click, D
go := True
MouseMove, A_ThisHotkey = "+F13" ? 0:0, ? -2:2,, R
SetTimer, Stop3, -400
Return
Stop3:
Click, U
go := False
Retur
User avatar
mikeyww
Posts: 26871
Joined: 09 Sep 2014, 18:38

Re: Click down Mouse and move.

10 May 2021, 05:46

It must be the syntax error doing that! :)

Code: Select all

MouseMove, 0, A_ThisHotkey = "+F13" ? -2 : 2,, R
Explained: MouseMoveTernary operator
arbibarbarona
Posts: 63
Joined: 05 May 2021, 10:19

Re: Click down Mouse and move.

10 May 2021, 07:45

mikeyww wrote:
10 May 2021, 05:46
It must be the syntax error doing that! :)

Code: Select all

MouseMove, 0, A_ThisHotkey = "+F13" ? -2 : 2,, R
Explained: MouseMoveTernary operator
Thank you so much. This is a great help.
arbibarbarona
Posts: 63
Joined: 05 May 2021, 10:19

Re: Click down Mouse and move.

06 May 2022, 14:26

Hello, I want to add a follow-up question regarding this script.

Is there a way that after I bind the targeted XY mouse coordinate to the corresponding key that it will save that mouse XY binding along with this script? so it will be saved even if I restart Autohotkey? The only reset is when I repeat the Keybinding steps again on a certain key or all keys. Thus the Script is saved again with a new keybinding?

Code: Select all

suspend, On

pos := {}
*1::
*2::
*3::
*4::
*5::
*6::
*7::
*8::
*9::
*0::
*F1::
*F2::
*F3::
*F4::
*F5::
*F6::
*F7::
*F8::
*F9::
*F10::
*F11::
*F12::
*Numpad0::
*Numpad1::
*Numpad2::
*Numpad3::
*Numpad4::
*Numpad5::
*Numpad6::
*Numpad7::
*Numpad8::
*Numpad9::
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

^Left::
^Right::
If !go
 Click, D
go := True
MouseMove, A_ThisHotkey = "^Left" ? -5:5, 0,, R
SetTimer, Stop, -200
Return
Stop:
Click, U
go := False
Return

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



!p::
Suspend, Off
SoundBeep, 2000
Return

!o::
Suspend, On
SoundBeep, 500
return

Esc::ExitApp
User avatar
mikeyww
Posts: 26871
Joined: 09 Sep 2014, 18:38

Re: Click down Mouse and move.

06 May 2022, 14:46

If you want to save your data and then retrieve them, you could use :arrow: IniWrite.
arbibarbarona
Posts: 63
Joined: 05 May 2021, 10:19

Re: Click down Mouse and move.

06 May 2022, 14:54

Or maybe add a simple GUI to assign those mouse coordinate to the Corresponding KEY then save it to the Script?
Attachments
GUI.jpg
GUI.jpg (23.73 KiB) Viewed 875 times
User avatar
mikeyww
Posts: 26871
Joined: 09 Sep 2014, 18:38

Re: Click down Mouse and move.

06 May 2022, 15:03

The answer to :?: would be to test your script and see if it works.
arbibarbarona
Posts: 63
Joined: 05 May 2021, 10:19

Re: Click down Mouse and move.

06 May 2022, 15:08

mikeyww wrote:
06 May 2022, 14:46
If you want to save your data and then retrieve them, you could use :arrow: IniWrite.
I may need your help implementing in my script above as I don't really know how. I've been reading Iniwrite but I can't get around it.

I would really appreciate your help Mike.

Thank you so much.
arbibarbarona
Posts: 63
Joined: 05 May 2021, 10:19

Re: Click down Mouse and move.

06 May 2022, 15:10

The Script above does work. But I want to Save the coordinate so I can recall it every time I use the script or modify the Coordinate from time to time and recall.
User avatar
mikeyww
Posts: 26871
Joined: 09 Sep 2014, 18:38

Re: Click down Mouse and move.

06 May 2022, 15:41

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
}

save(exitReason, exitCode) {
 For key, pair in pos
  For axis, coord in pair
   IniWrite, %coord%, %ini%, %key%, %axis%
 SoundBeep, 1000
}
arbibarbarona
Posts: 63
Joined: 05 May 2021, 10:19

Re: Click down Mouse and move.

06 May 2022, 20:24

So I will just change script path and name then append this script to my script ? or this is a separate script and add a line in my original script?
User avatar
mikeyww
Posts: 26871
Joined: 09 Sep 2014, 18:38

Re: Click down Mouse and move.

06 May 2022, 21:52

It's a demonstration of reading & writing. I would put the save function at the bottom of your script, and the rest at the top. You can delete line 3 of your current script.
arbibarbarona
Posts: 63
Joined: 05 May 2021, 10:19

Re: Click down Mouse and move.

07 May 2022, 02:41

Thank you so much, Mike. This has been a great help.
arbibarbarona
Posts: 63
Joined: 05 May 2021, 10:19

Re: Click down Mouse and move.

22 May 2022, 10:08

Code: Select all

^Left::
^Right::
If !go
 Click, D
go := True
MouseMove, A_ThisHotkey = "^Left" ? -5:5, 0,, R
SetTimer, Stop, -200
Return
Stop:
Click, U
go := False
Return

^Up::
^Down::
If !go
 Click, D
go := True
MouseMove, 0, A_ThisHotkey = "^Up" ? 5 : -5,, R
SetTimer, Stop2, -200
Return
Stop2:
Click, U
go := False
Return
Hello Mike, I have a question regarding this code. It works fine with Horizontal Click-Drag move action. But I have trouble with the Vertical Click-Drag. I wanna ask what have I missed? or is there a way simpler than this? Thank you so much. All I need is left click down on the current mouse coordinate and move the mouse either up or down then release the Left Click up.
User avatar
mikeyww
Posts: 26871
Joined: 09 Sep 2014, 18:38

Re: Click down Mouse and move.

22 May 2022, 10:20

I think you would want a variable other than go in your Up/Down routines, though it is not necessarily an error if your key sequences are never mixed or colliding.

Conceptually, "up" in screen direction generally corresponds to a decrease in the y-value.
arbibarbarona
Posts: 63
Joined: 05 May 2021, 10:19

Re: Click down Mouse and move.

31 May 2022, 03:39

Hello Mikey,

How Can I add in the script that when I hold down the Target key ie... ( F1), the cursor which I assiged in {*F1} will execute the mouse coordinate move and Hold down the Mouse Left button then released when held up?

Thank you in advance

Code: Select all

SoundBeep, 500, 100
SoundBeep, 1000, 500
Tooltip, You have loaded the Color Script - Press ACTIVATE to proceed.

suspend, On

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
}


*1:: ; Temp Primaries Wheel
*2:: ; Tint
*3:: ; Contrast
*4:: ; Pivot
*5:: ; Mid Details
*6:: ; Color Boost
*7:: ; Shadows
*8:: ; Highlights
*9:: ; Saturation
*0:: ; Hue
*F1:: ; Luma Mix
*F2:: ; Lift Scroll
*F3:: ; Lift Red
*F4:: ; Lift Green
*F5:: ; Lift Blue
*F6:: ; Gamma Scroll
*F7:: ; Gamma Red
*F8:: ; Gamma Green
*F9:: ; Gamma Blue
*F10:: ; Gain Scroll
*F11:: ; Gain Red
*F12:: ; Gain Green


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



^Left::
^Right::
If !go
 Click, D
go := True
MouseMove, A_ThisHotkey = "^Left" ? -10:10, 0,, R
SetTimer, Stop, -400
Return
Stop:
Click, U
go := False
Return

^Up::
^Down::
If !move
 Click, D
move := True
MouseMove, 0, A_ThisHotkey = "^Down" ? 10:-10,, R
SetTimer, Stop2, -400
Return
Stop2:
Click, U
move := False
Return



!+p::
Suspend, Off
SoundBeep, 2000, 500
Tooltip, Ready to COLOR? Script ACTIVATED!
Sleep, 1500
Tooltip,
Return

!+o::
Suspend, On
SoundBeep, 500
ToolTip, Color Script SUSPENDED. Keyboard Restored.
Sleep, 1500
Tooltip,
return

!End::
Suspend, Permit
If (A_ThisHotkey = A_PriorHotkey and A_TimeSincePriorHotkey < 200)
	if !A_IsSuspended
	{
		SoundBeep, 1000
		Suspend, On
	}
	else
	{
		Suspend, Off
		Sleep, 150
    }
Return

+Esc::
tooltip, EXIT Script, 810, 548
Sleep, 1000
tooltip,
ExitApp
return



~::
 For key, pair in pos
  For axis, coord in pair
   IniWrite, %coord%, %ini%, %key%, %axis%
 SoundBeep, 500
 SoundBeep, 1000
 tooltip, Successfully saved your SETTINGS, 810, 548
Sleep, 3000
tooltip,

save(exitReason, exitCode) {
 For key, pair in pos
  For axis, coord in pair
   IniWrite, %coord%, %ini%, %key%, %axis%
 SoundBeep, 1000, 100
 SoundBeep, 500, 250
}
User avatar
mikeyww
Posts: 26871
Joined: 09 Sep 2014, 18:38

Re: Click down Mouse and move.

31 May 2022, 12:44

I am not following the description, but give it a go. See Gosub to learn how to call another labeled subroutine. KeyWait is one way to wait for a key to be released. You might want to try a simple separate script first, that uses a hotkey to move the mouse and then wait for the hotkey to be released. That will get you started.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Noitalommi_2, ulysim and 306 guests