Looking for help - Mouse button down - Release on key press Topic is solved

Ask gaming related questions
Paintbrush30mm
Posts: 2
Joined: 07 Apr 2024, 09:59

Looking for help - Mouse button down - Release on key press

07 Apr 2024, 10:42

Years ago I found this

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
l::Click % GetKeyState("LButton") ? "Up" : "Down"
It was the only script that would on key press reliably hold the mouse button down and release on a second key press.
In v2 this no longer works although I saw GetKeyState.
Would it be possible to have that for both mouse buttons in one script executable, with different keys, of course?

This script was amazing for accessibility so any help would very appreciated
User avatar
boiler
Posts: 17120
Joined: 21 Dec 2014, 02:44

Re: Looking for help - Mouse button down - Release on key press  Topic is solved

07 Apr 2024, 13:11

Try this, which adds the safety feature of releasing both buttons upon script exit so they're not stuck open.

Code: Select all

#Requires AutoHotkey v2.0

l::Click GetKeyState('LButton') ? 'Up' : 'Down'

r::Click GetKeyState('RButton') ? 'Right Up' : 'Right Down'

Esc::ExitApp

OnExit (*) => (Click('Left Up'), Click('Right Up'))


It might help to have audio feedback to help make clear an action was taken. You might want to also add a visual indicator of the state of each button.

Code: Select all

#Requires AutoHotkey v2.0

l:: {
	if GetKeyState('LButton') {
		Click 'Up'
		SoundBeep 500
	} else {
		Click 'Down'
		SoundBeep 300
	}
}

r:: {
	if GetKeyState('RButton') {
		Click 'Right Up'
		SoundBeep 600
	} else {
		Click 'Right Down'
		SoundBeep 400
	}
}

Esc::ExitApp

OnExit (*) => (Click('Left Up'), Click('Right Up'))
Paintbrush30mm
Posts: 2
Joined: 07 Apr 2024, 09:59

Re: Looking for help - Mouse button down - Release on key press

14 Apr 2024, 03:46

Boiler! Thank you so much. This has been a great help. It works perfectly and exactly as I hoped.
Instant on/off, no lag. Glorious.
Please excuse the late reply.
Have a great day, week, year!
Cheers!

Return to “Gaming”

Who is online

Users browsing this forum: DaveyW and 7 guests