Need help about a region of the screen, please.

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
rno2007
Posts: 4
Joined: 08 Feb 2023, 19:30

Need help about a region of the screen, please.

Post by rno2007 » 08 Feb 2023, 19:38

Dear Autohotkey community,

I am a beginner trying almost a week to solve this problem but unsuccessful.
My screen is 1920x1080.
I need a Numpad5 to activate
a mouse left click and hold when the mouse pointer is on outside the box
and mouse right click in every 0.5 second when the mouse pointer is inside the box.

Could anyone help me this please? Thank you in advance.

Image

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

Re: Need help about a region of the screen, please.

Post by mikeyww » 08 Feb 2023, 20:54

Welcome to this AutoHotkey forum!

Ideas:

Code: Select all

#Requires AutoHotkey v2.0
winTitle := "ahk_class MSPaintApp"
rclik    := () => Send('{LButton up}{RButton}')
OnExit done

#HotIf WinActive(winTitle)
Numpad5::SetTimer check, 100
#HotIf
Esc::ExitApp

check() {
 Static last := "", inside := "", str := ""
 MouseGetPos &x, &y
 last := inside, inside := x > 800 && x < 1120 && y > 400 && y < 680
 If !inside {  ; Outside box
  SetTimer rclik, 0
  Send GetKeyState("LButton") ? "" : "{LButton down}"
  str := 'LButton down'
 } Else (inside != last) && (SetTimer(rclik, 500), rclik(), str := 'RButton')
 ToolTip('(' x ', ' y ')`n' str)
}

done(exitReason, exitCode) {
 Click 'U'
 SoundBeep 1500
}

rno2007
Posts: 4
Joined: 08 Feb 2023, 19:30

Re: Need help about a region of the screen, please.

Post by rno2007 » 09 Feb 2023, 19:19

mikeyww wrote:
08 Feb 2023, 20:54
Welcome to this AutoHotkey forum!

Ideas:

Code: Select all

#Requires AutoHotkey v2.0
winTitle := "ahk_class MSPaintApp"
rclik    := () => Send('{LButton up}{RButton}')
OnExit done

#HotIf WinActive(winTitle)
Numpad5::SetTimer check, 100
#HotIf
Esc::ExitApp

check() {
 Static last := "", inside := "", str := ""
 MouseGetPos &x, &y
 last := inside, inside := x > 800 && x < 1120 && y > 400 && y < 680
 If !inside {  ; Outside box
  SetTimer rclik, 0
  Send GetKeyState("LButton") ? "" : "{LButton down}"
  str := 'LButton down'
 } Else (inside != last) && (SetTimer(rclik, 500), rclik(), str := 'RButton')
 ToolTip('(' x ', ' y ')`n' str)
}

done(exitReason, exitCode) {
 Click 'U'
 SoundBeep 1500
}
Thank you so much for your wonderful code. It works perfectly. Thank you.

Post Reply

Return to “Ask for Help (v2)”