How do I create a macro Snippet to send special keys to applications or insert pauses when pasting?

This page has been updated for Quick Access Popup v10.

The Macro snippets are for users with some experience with scripting language. To create a macro snippet, open the snippet's Advanced Settings tab in the Add/Edit favorite dialog box and select Macro mode. In this mode, instead of pasting the snippet, QAP sends its content to the active application as keystrokes that you would type at the keyboard.

Special keys and commands

Macro snippets support the special keys (defined by scripting language AutoHotkey) allowing to send special keystrokes like Backspace, Home, Control, etc. These special keys are always enclosed between curly brackets, for example: {Backspace}.

In addition, QAP offers some special commands for macro snippets:

  • {&Sleep:n} or {&n}: pause sending the snippet for n milliseconds (see AHK Sleep documentation)
    For example: {&Sleep:1000} or {&1000} to insert a one second pause while sending the snippet
  • {&SetKeyDelay:n, option}: slow down the execution of the snippet (see AHK SetKeyDelay documentation)
    For example: {&SetKeyDelay:50} to insert a 50 ms delay between each keystroke in the snippet
  • {&KeyWait:keyname, options}: pause sending the snippet until user press the specified key (see AHK KeyWait documentation, option D is set by default, additional option B available to sound "Beep" when snippet is suspended)
    For example: {&KeyWait:Space,B} to stop the macro snippet execution, sound "beep" and wait until user pushes down the space bar
Macro Snippet Working Example

Here is a full working macro snippet example. This macro snippet will launch Notepad, beep and wait for the space bar keypress, type some text, wait for the Shift keypress, add some text and open the Notepad Save dialog box:

{&SetKeyDelay:50}#r{&500}notepad{Enter}{&KeyWait:Space,B}
{Backspace}You are in Notepad{!}
Choose a location to save this file...{&500}^s

 

  • {&SetKeyDelay:50} : slow down the snippet execution with a 50 ms delay between each keystroke
  • #r : press Windows + R to open the Windows Run dialog box
  • {&500} : insert an half-second pause
  • notepad{Enter} : type notepad and press Enter to launch Notepad
  • {&KeyWait:Space,B} : beep and wait for the space bar keypress
  • You are in Notepad : type this text
  • {!} : type the exclamation mark (enclosed because "!" is an AHK special character, see AHK doc)
  • Choose a location to save this file... : type this text
  • {&500} : wait for another half-second
  • ^s : press Control + S to open the Notepad Save dialog box

Placeholders in macro snippets: You can use the Windows Clipboard, user input or the current date-time to insert variable pieces of text in your snippets. For example, when you launch your favorite, QAP automatically replaces the placeholder {Clipboard} with the current content of the Windows Clipboard. Placeholders can also be replaced with various file locations. See Can I insert values in favorites location, parameters or snippets using placeholders?

Prompt before launching the macro snippet: In the Advanced Settings tab, you can enter text in Prompt before launching the snippet that will be displayed with a prompt to hit Enter or Space to launch the snippet, or Esc to cancel it. The prompt can include placeholders.

Macro programming experience is strongly recommended before using this feature. If you need help writing AHK macro, I recommend searching answers or asking question in the "Ask for help" section of the AHK forum where you will find plenty of knowledgeable people who love helping new macro programmers. You can also learn it with these books.

Can I insert command from the AHK programming language in a snippet of type macro? A QAP macro snippet favorite can send pieces of text and basic commands to your keyboard using the SendInput AHK command. However, it is not the place for full-fledge AHK macro language. Variables, conditional expressions (if), loops, etc. are not supported in macro snippet. But you can easily write an AutoHotkey macro using a text editor, save it in a file with .ahk extension and launch your AHK macro from QAP. To do this, create a QAP favorite of type Application and enter the location of your script (for example c:\AHKscripts\myscript.ahk) in the Application (path and file name).

See also:

Please use the new QAP Support Forum to ask questions or post comments.