Presses a single key, or a single dash-separated key combination. It is meant for usage in custom functions in tandem with other operations such as Str, as opposed to Key that is most often used directly in a Context's keymap.
press(key_string)
key_string - String containing a single key or key combination
Returns - None
When called, the provided key string, or key combination string, is executed immediately.
A single key string simply presses the corresponding key, such as the string 'k', which will press the K key.
A key combination is a dash-separated set of modifier keys followed by a single non-modifier key. For example, 'cmd-shift-s' would hold the Command key (⌘) and the Shift key (⇧), and then press the S key.
Check the Keys List for a list of all key name strings.
Modifier Key Name | Key String | Example | |
---|---|---|---|
⌃ | Control | ctrl | 'ctrl-c' |
⌥ | Alt/Option | alt | 'alt-tab' |
⌘ | Command | cmd | 'cmd-s' |
⇧ | Shift | shift | 'cmd-alt-shift-v' |
Fn Key (Modifier) | fn | 'fn-f2' |
from talon.voice import press
Unlike Key, press is typically used in tandem with other operations in custom functions. It is not meant to be used directly in a Context keymap.
press('cmd-s')
Immediately presses ⌘ + s, which will perform a Save operation in most apps.
This example makes additional use of Str.
press('cmd-up')
press('enter')
press('cmd-up')
press('cmd-/')
Str('Copyright 2018')(None)
press('cmd-left')
This sequence would be executed as a custom function triggered by a Rule. It would be something that might execute in a code editor using fairly standard keyboard shortcuts. Here's how it works:
- ⌘ + ↑ - moves the cursor to the beginning of the first line of text
- \n - makes a new line
- ⌘ + ↑ - moves the cursor to the beginning of the newly created first line of text
- ⌘ + / - inserts the comment syntax for the current language (such as '//' or '#')
- Inserts the "Copyright 2018" string
- ⌘ + ← - moves the cursor to the beginning of the line