capnhud
capnhud

Reputation: 465

Combining two sequences of keystrokes using autohotkey

I would like to send a sequence of keystrokes using just one key to accomplish certain task in sublime text 2 using autohotkey. To set a mark in sublime text 2 the key sequence is Ctrl+K followed by Ctrl+Space. I tried

#IfWinActive, ahk_class PX_WINDOW_CLASS
Numpad0::Send ^k sleep 5, Send ^+Space
#IfWinActive

which will activate the first part of the sequence but has the side effect of also typing send sleep 5, Send and trying to save the file which I am not trying to do.

If I remove the (sleep 5, Send ^+Space) I then have to push Ctrl+Space to finish off the sequence in order to set the mark. What do I need to add after the Ctrl+K to accomplish the ability to set a mark in sublime text with autohotkey?

Upvotes: 1

Views: 1456

Answers (2)

Robert Ilbrink
Robert Ilbrink

Reputation: 7953

Inside #IfWinActive, you can use multiple lines this way.

#IfWinActive, ahk_class PX_WINDOW_CLASS
Numpad0::
    Send, ^k ; Send Ctrl k
    Sleep, 5 ; Wait 5 ms (probably too short, I would use 400 ms)
    Send, ^+{Space} ; Send Ctrl Shift Space
Return
#IfWinActive

Added Curly brackets around Enter!

Upvotes: 1

Elliot DeNolf
Elliot DeNolf

Reputation: 2999

When Send is used, it will try to send the rest of the line. That would be why the rest is being typed. However, I tried splitting them up, and it still did not function correctly.

The following works for me, give it a try:

#IfWinActive, ahk_class PX_WINDOW_CLASS
    Numpad0::Send, {CTRLDOWN}k{CTRLUP}{CTRLDOWN}{SPACE}{CTRLUP}
#IfWinActive

Upvotes: 2

Related Questions