Skip to content

Win Key Press

Type: win-key-press  ·  Package: Desktop Activities v1.0.8

Sends a key, a combination or a sequence of combinations to the application: shortcuts like ctrl+s (save), alt+f4 (close), f5 (refresh), keys like enter and tab, or several in a row like ctrl+a, ctrl+c (select all and copy). Essential to operate desktop apps that rely on keyboard shortcuts.

  • Combinations: modifiers and the key are joined with + (e.g. ctrl+shift+n). Each combination has a single main key. Case doesn’t matter (Ctrl+S = ctrl+s).
  • Sequences: several combinations are separated with commas and sent in order, with a 60 ms pause between them so the app processes each one (e.g. home, shift+end selects the current line).
  • With selector: it first locates the element (up to timeout), brings its window to the front (waiting up to 3 s) and focuses it; then it sends the keys. If the window can’t be brought to the front, nothing is sent and the activity fails (so keys never end up in another application). If another window takes the focus halfway through a sequence, the sequence stops there and the activity fails saying how many combinations were sent.
  • Without selector: the keys go to whichever window has the focus at that moment, and session is not used. Bring the right window forward first with Win Focus.

Editing and navigation keys are sent the way a real keyboard sends them, so selections work just like by hand: shift+end, shift+home or ctrl+shift+right select text correctly. The log only records how many combinations were sent, not which (they may contain a code or a PIN).

KindNames
Modifiersctrl (or control), alt, shift, win (or windows)
Letters and digitsa–z, 0–9
Editing and navigationenter (or return), tab, esc (or escape), space, backspace, delete (or del), insert (or ins), home, end, pageup (or pgup), pagedown (or pgdn), up, down, left, right
Function keysf1–f24
Systemprintscreen (or prtsc), pause (or break), capslock, numlock, scrolllock, menu (context menu key; also apps)
Numeric keypadnum0–num9 (or numpad0–numpad9), multiply, add, subtract, decimal, divide
Symbols by nameplus, minus (or dash), comma, period (or dot), slash, backslash, semicolon, quote, equals, backquote (or backtick), openbracket, closebracket
Symbols as typed- . / ; = ' [ ] \ `

Symbols are translated with the machine’s keyboard layout: if that layout needs Shift or AltGr for the symbol, they are added automatically. So plus works the same on a Spanish keyboard (where + has its own key) as on an English one (where it is Shift + =).

ParameterTypeDefaultDescription
keysstring—Key, combination or comma-separated sequence. E.g. ctrl+s, alt+f4, enter, f5, ctrl+shift+n, ctrl+a, ctrl+c.
ParameterTypeDefaultDescription
sessionZoanDesktopSession—Win Attach session, to search for selector inside its window. Inside a body it is taken automatically. Not used without selector.
selectorselector—Element to focus before sending the keys. Empty = keys go to the active window.
timeoutnumber30000Maximum ms to wait for the element (if there is a selector). Empty = the project’s UI timeout or, if not set, 30000.

This activity does not return a value.

MessageCause and fix
Unknown key: '…'. See the parameter help for the key names.A key name doesn’t exist, or the symbol is not in the machine’s keyboard layout. Check the key table.
'…' has more than one main key. Use commas to send keys one after another (e.g. 'ctrl+a, ctrl+c').A combination like a+b. Separate them with commas.
No main key specified in '…'.A combination with only modifiers (ctrl+shift). Add the key.
'keys' is empty. / 'keys' is required.There are no keys to send.
Could not bring the element's window to the front, so no keys were sent (they would have gone to another window). …The window is behind a dialog, minimized, or runs as administrator. Close the dialog or check the permissions.
Another window took the focus after … of … key combinations; the rest were not sent.Another window appeared halfway through the sequence. Wait for things to settle with Win Wait For and retry.
Windows rejected the keystrokes (error …). …The target window runs as administrator and the robot doesn’t, or the session is locked.
Element not found with selector {…}.See common errors.

Save with Ctrl+S and confirm a dialog with Enter:

Win Key Press selector = (text area) keys = "ctrl+s"
Win Wait For selector = (dialog "Confirm") state = visible
Win Key Press selector = (button "OK") keys = "enter"

Select the current line of a text field:

Win Key Press selector = (field "Notes") keys = "home, shift+end"

Copy a field’s whole content and paste it into another:

Win Key Press selector = (field "Source") keys = "ctrl+a, ctrl+c"
Win Key Press selector = (field "Target") keys = "ctrl+v"

Type a number with the numeric keypad and move to the next field:

Win Key Press selector = (field "Quantity") keys = "num1, num2, num0, tab"
  • Win Type — type text (not special keys).
  • Win Focus — bring the right window to the front before sending keys without a selector.
  • Win Click — the alternative with a button.