Execute Rest of Script On Release of Modifier Key

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
tatleoat
Posts: 24
Joined: 16 Mar 2021, 14:54

Execute Rest of Script On Release of Modifier Key

24 Jul 2021, 22:01

Hello all,

I'm trying to execute a code that draws an ellipse on screen by the mouse pointer every time I use ^LButton. The cool feature of this is I can just keep Control held down and click all over and draw a bunch of ellipses without having to release control every time. I want to take advantage of the control key so that when I finally release it my computer will press the PrintScreen key and take a screenshot of the screen, ellipses and all. The only issue is I can't get it to respond to the release of control, any ideas?

Here's the code that I'm using right now, in conjunction with the GDIP library and a tutorial I found online (Found at https://juho-lee.com/archive under "Other Useful Scripts #8 Draw Live on Screen"):

Code: Select all

;Draw ellipse
^LButton::   
CoordMode, Mouse, Screen
while GetKeyState("LButton", "P") {
MouseGetPos, x1, y1
x1 -= 55
y1 -= 30
BitBlt(hdc3, 0, 0, Width, Height, hdc, 0, 0) ; save previous hdc first


  MouseGetPos, x2, y2
x2 += 110
y2 += 60
  Gdip_GraphicsClear(G2)
  BitBlt(hdc2, 0, 0, Width, Height, hdc, 0, 0) ; BitBlt first before drawing
  ;seems to expect the (x,y) coordinates passed to always be the upper left corner and width,height to be positive
  Gdip_DrawEllipse(G2, pPen, min(x1,x2), min(y1,y2), abs(x2-x1), abs(y2-y1))
  UpdateLayeredWindow(hwnd7, hdc2, 0, 0, Width, Height)




step:=["0x" LA ColorList[Handles[LH]],LT,"Gdip_DrawEllipse",min(x1,x2),min(y1,y2),abs(x2-x1),abs(y2-y1)]
steps.push(step)

  BitBlt(hdc, 0, 0, Width, Height, hdc2, 0, 0) ;copy buffer to screen
  UpdateLayeredWindow(hwnd7, hdc, 0, 0, Width, Height) ; now draw on screen
}
return
As always thank you so much for always coming through for me when I post here, it's always incredibly appreciated.
User avatar
mikeyww
Posts: 26855
Joined: 09 Sep 2014, 18:38

Re: Execute Rest of Script On Release of Modifier Key

24 Jul 2021, 22:51

Before Return, you could add:

Code: Select all

KeyWait, Ctrl
Put your new code after that. If you click on "KeyWait" in the code block posted above, you will see an explanation.
tatleoat
Posts: 24
Joined: 16 Mar 2021, 14:54

Re: Execute Rest of Script On Release of Modifier Key

25 Jul 2021, 06:06

I thought that might have been the answer too but unfortunately when I try to ctrl click more than once to add multiple ellipses it doesn't add more than one. If there was a way to get the hotkey to force restart every time I click then something like that might work
User avatar
mikeyww
Posts: 26855
Joined: 09 Sep 2014, 18:38

Re: Execute Rest of Script On Release of Modifier Key

25 Jul 2021, 08:09

In that case, you can use an "Up" hotkey. A demo is below.

Code: Select all

^LButton::Send 1
~Ctrl Up::Send 2
tatleoat
Posts: 24
Joined: 16 Mar 2021, 14:54

Re: Execute Rest of Script On Release of Modifier Key

25 Jul 2021, 09:54

Wow that's really simple and works great, thank you
User avatar
mikeyww
Posts: 26855
Joined: 09 Sep 2014, 18:38

Re: Execute Rest of Script On Release of Modifier Key

25 Jul 2021, 10:31

You are welcome. You might want to add some condition so that the Ctrl Up does not trigger in other circumstances. One example is below.

Code: Select all

^LButton::
on := True
Send 1
Return

#If on
~Ctrl Up::
Send 2
on := False
Return
#If

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Chunjee, mikeyww and 292 guests