4

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?

Sakuya
  • 660
  • 5
  • 23
  • Good question. +1 Wish I knew what to tell you. Well, in your current script, if capslock is OFF, it sends a left-click because that's what you are telling it to do. If you want it to ignore the left click, then don't send `LButton`, - I think I'm missing your point. – bgmCoder Dec 03 '13 at 01:43

2 Answers2

2

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.

MCL
  • 3,985
  • 3
  • 27
  • 39
0

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
this
  • 5,229
  • 1
  • 22
  • 51