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.
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
Any idea or comment are appreciated!
How to use MouseClickDrag as HOTKEY (NOT ACTION)
Re: How to use MouseClickDrag as HOTKEY (NOT ACTION)
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.
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.
Re: How to use MouseClickDrag as HOTKEY (NOT ACTION)
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
Last edited by swagfag on 24 May 2018, 11:24, edited 1 time in total.
Re: How to use MouseClickDrag as HOTKEY (NOT ACTION)
That is super smart! thank you so much swagfag!