Conditionally intercept a mouse click in Autohotkey?

1.2k views Asked by At

I want to have a script which will intercept a mouse click and send a key press instead, but only when the capslock key is toggled on. I want the mouse click to be sent normally if the capslock key is toggled off.

Currently I have made this:

$LButton::
if GetKeyState("CapsLock", "T") = 1
    send, {a}
else
    send, {LButton}
return

The problem with this is that when the capslock key is off, the left button can click perfectly normally but it cannot drag.

If I change $ to ~, it is able to drag but it also performs a click when the capslock key is toggled on.

Is there any way to make the script ignore the click completely if the capslock key is toggled off?

2

There are 2 answers

0
MCL On BEST ANSWER

AHK_L's #If will give you what you want:

#If GetKeyState("CapsLock", "T")
LButton::Send, a

With this code, you won't have to bother what happens when capslock is off. AHK will intercept the click on a lower level and let it trickle through.

0
this On

How to use the symbol UP.

SetBatchLines, -1   ; you pretty much have to include this to speed up the execution

LButton::
    if( GetKeyState("CapsLock", "T") )
        tooltip, ignore left click
    else
        send, {LButton Down}
return


LButton UP::
    send, {LButton Up}
return