How to bind a key to left mouse button perfectly?

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.

長谷川夕実

Posted 2018-05-31T02:12:59.073

Reputation: 1

Answers

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.

PloxPanda

Posted 2018-05-31T02:12:59.073

Reputation: 118

Explain your answer with the syntax used in that AHK script. – Biswapriyo – 2018-05-31T03:47:21.530

@Biswapriyo There we go cleaned it up abit turns out there is MouseClick and Click – PloxPanda – 2018-05-31T04:02:02.673

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.

Abr001am

Posted 2018-05-31T02:12:59.073

Reputation: 101