0

I am very new to AutoHotkey and I want to know if it's possible to bind a keyboard key to mouse left button one to one? Like if I hold down the key assigned to left click it would hold as if I'm holding/dragging it with the left mouse button? And if I release it, it will release as well. Also, is there any other way to do this other than AutoHotkey?

Example:

c::
MouseClick, Left

But if I click and hold down C it starts repeating the left click rapdily instead of holding it down as long as I hold C.

Any help is greatly appreciated.

0

MouseClick is mostly used for Clicking a certain location and mostly looks like this

MouseClick, left, 55, 233

It will still work when you use this code below

c:: MouseClick, Left

It will Click when you Press C however if you hold down the C key it will constantly spam click you can fix this issue by using Click, Down as shown below

c:: Click, down

Now when the C key is pressed it will Click once and hold it while the C key is pressed down activing like the mouse button

There is more information about how the mouse clicks work with AHK here.

  • Explain your answer with the syntax used in that AHK script. – Biswapriyo May 31 '18 at 3:47
  • @Biswapriyo There we go cleaned it up abit turns out there is MouseClick and Click – PloxPanda May 31 '18 at 4:02
0

Following what is given by @Plox that halffills what is required by this post, more to be elucidated if we realise that c:: MouseClick left,,,,, D works by the same mechanism used by:

c::
MouseClick left,,,,, D
return

The AHK engine here fires a MouseDown, gets out of this thread and hooks up to User Input again waiting another action, that says if the key is still held, AHK will gets infinitely into the same routine when it realises that the hotkey triggering it is still pressed.

More of two palliatives can be used:

  • You choose to seep AHK busy until releasing the same kay:

    c::
    MouseClick left,,,,, D
    Keywait, c, U
    MouseClick left,,,,, U
    return
    
  • Or you prefer keeping AHK interpreter free outside of the same routine, by reserving a gloval variable keybound to forbid revolving into the same action over again if the key is not made free yet.

    #HotkeyInterval 0
    
    keybound:=0
    
    c::
    if keybound
    return
    keybound:=1
    MouseClick left,,,,, D
    return
    
    c Up::
    MouseClick left,,,,, U
    keybound:=0
    return 
    

HotkeyInterval is some threshold switched off to prevent undesired warns.

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.