1

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.

2

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.

One of two palliatives can be used:

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

      c::
      MouseClick left,,,,, D
      Keywait, c, U
      MouseClick left,,,,, U
      return
    
  • Or you can 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 2000  ; Reset to default value
    

HotkeyInterval is some threshold switched off to prevent undesired warns.

1

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.

0

here's my script work well:

$*space::
    ;  SetKeyDelay -1
      click down
      ; keywait, %A_ThisHotkey%
      ; keywait, CapsLock
      keywait, space 
    ;  Send {Blind}{lbutton DownTemp}
return

*$space up::  
  click up
return

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.