Press keyboard keys, type text

Syntax1

key[+|-] keys

 

Syntax2

'keys

 

Remarks

Generates keyboard events. It works like you would press keyboard keys manually.

 

Syntax2 can be used to make the code shorter.

 

Tip: Before reading further, see examples at the bottom of this topic.

 

keys can include any number of parts of these types:

 

1. Parts without quotes and parentheses. Use uppercase letters to press special keys. For other keys use lowercace letters and other characters. Characters ;"{}() have special meaning - instead use :'[]90 or enclose in double quotes. To press a key together with one or several modifier keys (Ctrl, Shift, Alt, Win), use one or several modifier keys followed by that key. For example, Sa means Shift+A ; CAF2 means Ctrl+Alt+F2. Several keys can be enclosed in {}. For example, A{ev} means Alt+E+V.

 

2. Text in double quotes. The text is typed as simple text (without special keys). When QM is running in Unicode mode, Unicode characters also can be used.

 

3. String expression (e.g., variable) in parentheses. The value of the expression is typed as simple text (like in case 2).

 

4. Windows virtual-key code (integer value, 8 to 255) in parentheses. For example, key (44). Virtual-key codes are defined as VK_ constants, and you can use them with key. For example, key (VK_SNAPSHOT). The value also can contain the following flags: 0x10000 - low-order byte is scan code; 0x20000 - extended key (usually used together with scan code).

 

5. Unicode character code (integer value, 0x100 to 0xFFFF) in parentheses. By default, to type the character is used Alt+numpad. You can use flag 0x40000 to type it without using Alt+numpad. Then the value also can be less than 0x100. Note that in Unicode mode you can instead simply use Unicode characters in text enclosed in double quotes (read above). Then Alt+numpad is not used.

 

6. Double (floating-point) expression in parentheses inserts delay.

 

In case 1 and 4, if used option character +, keys are pressed down but not released. If used -, keys are only released. QM 2.2.1: This also can be set in keys: (0x01000000) and (0x02000000).

 

QM 2.2.1: Can be used as function. Then it does not press keys, but instead returns virtual-key codes. Read more

 

Tips

You can use function BlockInput to block keyboard and mouse input while macro is running. Place BlockInput 1 at the beginning. If you want to manually end macro when input is blocked, at first press Ctrl+Alt+Delete.

If the user presses keys simultaneously with the key command, user-pressed keys may be inserted between key-pressed keys. To avoid it, use low level keyboard hook or opt keymark 1.

 

See also: Windows keyboard shortcuts, opt slowkeys, opt keysync, admin apps on Vista

 

Examples

key ab c F12 T Y      ;;A, B, C, F12, Tab, Enter
key Ca                ;;Ctrl+A
key CSf A{ec} Wd      ;;Ctrl+Shift+F, Alt+E+C, Win+D
key "Send Keys"       ;;type "Send Keys"
key SsendVSkeys       ;;type "Send Keys" using QM key codes
key (s)               ;;type string variable s
key (VK_F2)           ;;F2
key A(44)             ;;Alt+PrintScreen
key a (0.5) b         ;;A, wait 0.5 s, B
key (0x017e|0x40000)  ;;UNICODE character
key Skeys "Keys" A(44) AT (0.5) Cv A{fa} Y
'AT                   ;;Alt+Tab

 Ctrl+Shift+click:
key+ CS
lef
key- SC