0
votes

I have this code, and i want to whenever i hold ctrl+n it will click and drag. It doesn't loop with the Send commands in place. It only runs once, unless i let go of ctrl and n and press again. If i comment them out the hotkey loops perfectly fine when i hold it down. Heres my script:

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
#Warn  ; Enable warnings to assist with detecting common errors.
; SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.


^n::
CoordMode, Mouse, Screen
Send {LButton down} ;if i comment these two out it works fine
MouseMove, 0, 30, 20, R
Send {LButton up} ; ditto
return

1
Unable to replicate; it appears to work for me (i.e. it repeats fine). Mb try testing it in notepad to see if it is a software-specific issue? - Spyre
You might want to send {Ctrl Up} and the opposite too as some software will have different functions for Ctrl dragging items. - samthecodingman

1 Answers

0
votes

The problem was ctrl key. When pressed down it stops new execution of hotkey. I tried it without ctrl prefix and used just n:: and it worked fine. It also works if you press ctrl+n then release it then press it again. Anyways when you add Hotkey Modifier $ sign in front it works as you wanted.

Hotkey Modifier $ explanation:

This is usually only necessary if the script uses the Send command to send the keys that comprise the hotkey itself, which might otherwise cause it to trigger itself. The $ prefix forces the keyboard hook to be used to implement this hotkey, which as a side-effect prevents the Send command from triggering it. The $ prefix is equivalent to having specified #UseHook somewhere above the definition of this hotkey.

More info: https://www.autohotkey.com/docs/Hotkeys.htm

$^n::
CoordMode, Mouse, Screen
Send {LButton down}
MouseMove, 0, 30, 20, R
Send {LButton up}
return