kite
kite

Reputation: 313

ctrl+s not being sent in autohotkey script

i.e. hitting ctrl+s should activate ctrl+s...the below does not work. Neither does the simpler SendInput, ^s. Goal is to have ctrl+s save current doc and then load another via more code, the saving part never works tho. The bad code, depending on where i put sleep or no sleep, either returns s or shift s (in 1 code editor anyways) or nothing. I basically want a hotkey that mimics itself.

F4::ExitApp  
<^s::  
send, {lctrl down}  
SLEEP 300  
SEND s  
SLEEP 300  
SEND {lctrl up}  
return  

Upvotes: 5

Views: 2742

Answers (1)

Spyre
Spyre

Reputation: 2344

I would think that the issue your program is running into is that having the ^s send another ^s inside of itself is creating an infinite recursive loop in which nothing is ever able to run past the place you invoke ^s. To prevent this, we can use the $ modifier as so:

$<^s::  
SendInput ^s
return  

From the relevant section of the Modifier section of the docs:

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.


Edit: it seems to work fine for me even if I remove the $ modifier. Testing the following code shows me there appears to be no problems regarding code execution before, after, or during the SendInput statement.

<^s::  
MsgBox no
SendInput, ^s
MsgBox yes
return

Maybe check your version or installation of AHK?

Upvotes: 4

Related Questions