0
votes

I use an application everyday which listens out for double clicks of the control key. It also keymaps another function to a single click of the control key, and there is no way within the application to prevent or remap one or other function.

What I'd like to do is use AutoHotkey to prevent the application from responding to the double control click.

The application won't respond with the default double click behaviour if a mouse move is inserted between the two control keydown events.

Is there any way I can write an AutoHotkey script to listen for two sequential clicks of the control key, and insert a benign event (e.g. a mouse event) before the second control click?

I've tried the following code, but the second LControl is still getting through. Is there anyway to prevent the second LControl from getting through?

~LControl::
if (A_PriorHotkey <> "~LControl" or A_TimeSincePriorHotkey > 400)
{
    ; Too much time between presses, so this isn't a double-press.
    SendInput {LControl}
    return
}
MouseMove 5,5,10,R
;SendInput {LControl}
return
1
You can detect a double press by defining a "timeout" (400 ms is usually good). You can then check upon each keypress of the desired key, when the previous keypress occurred. If it was within the time frame, it is a double press.MCL
To your new code: Have a look at the hotkey docs. The tilde modifier ~ will always trigger a key's native function, that is, a CTRL keypress will trickle through by definition! Remove the modifier, LControl:: should do fine.MCL

1 Answers

-1
votes

Here's a method that I use to trigger an action when either the left or right control key is pressed quickly within 400 ms:

~Control Up::
  if ctrl_presses > 0
    ctrl_presses += 1
  else {
    ctrl_presses = 1
    SetTimer, CtrlPress, 400
  }
return

CtrlPress:
  SetTimer, CtrlPress, off
  if ctrl_presses = 2
    ; DO ACTION HERE
  ctrl_presses = 0
return

With this method you can easily trigger actions for not just a double-press, but even more.