How to use MouseClickDrag as HOTKEY (NOT ACTION)

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
arabia5
Posts: 2
Joined: 24 May 2018, 02:06

How to use MouseClickDrag as HOTKEY (NOT ACTION)

24 May 2018, 02:30

Hi my friends,

I am new here so maybe the question I am going to ask has been answered before but I can't find it by myself or from the official tutorial (https://autohotkey.com/docs/Hotkeys.htm). I know we can trigger MouseClickDrag in action, but here I would like to use it asHOTKEY. :roll:
Here is what I want to do:
I press Shift and at the same time left-click and drag my mouse from any position (x1, y1) to another position (x2,y2) as the hotkey, and I want this dragging to trigger an action that clicks the center point of the square within those two positions, namely (0.5*(x1+x2), 0.5*(y1+y2)). Is it something I can do with AutoHotkey? I don't know how to use dragging as hotkey, nor do I know how to cache two positions, (x1,y1) and (x2,y2), for further computation. I usually use "MouseGetPos, xpos, ypos " to capture one position of the mouse, but now we have two positions to capture :o

Any idea or comment are appreciated!
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: How to use MouseClickDrag as HOTKEY (NOT ACTION)

24 May 2018, 03:04

You have to think about it in terms of what mouse dragging broken down actually is. It's two events, namely the mouse being initially held down, then released, ie LButton:: and LButton Up::

So save the first set of coordinates when you press the mouse. Save the second set of coordinates when you release it and do your computation and finally mouse move action in there.
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: How to use MouseClickDrag as HOTKEY (NOT ACTION)

24 May 2018, 07:39

Code: Select all

#NoEnv
#SingleInstance Force
#MaxThreadsPerHotkey 2
SendMode Input
SetBatchLines -1
CoordMode, Mouse, Screen

$+LButton::
{
	MouseGetPos, xStart, yStart
	clickMidpoint := true
return
}

#If clickMidpoint
*LButton Up::
{
	MouseGetPos, xEnd, yEnd
	xMid := (xStart + xEnd) / 2
	yMid := (yStart + yEnd) / 2
	Click, %xMid%, %yMid%
	MouseMove, xEnd, yEnd, 0
	clickMidpoint := false
return
}
#If

Esc::ExitApp
e: forgot to add closing #If
Last edited by swagfag on 24 May 2018, 11:24, edited 1 time in total.
arabia5
Posts: 2
Joined: 24 May 2018, 02:06

Re: How to use MouseClickDrag as HOTKEY (NOT ACTION)

24 May 2018, 10:12

That is super smart! thank you so much swagfag!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], roysubs and 284 guests