3
votes

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  
1
Maybe try a combined character approach. Sending sequentially as you're doing probably won't cut it. autohotkey.com/board/topic/… - Atmas
you'll have to be more specific, ive tried all those things and read that post earlier. - kite
Ok. Then probably not useful. Apologies I was only looking at your above script which looked like a sequence of keys rather than a simultaneous press. - Atmas

1 Answers

2
votes

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?