This script shows how to invoke special keys on the keyboard and how to type unicode text.
Linked from:
- Christian Scheuer @chrscheuer2018-06-17 15:55:34.925Z
To press a (special) key based on its position on the keyboard (useful for invoking built in PT shortcuts), use this syntax with any of the key names from the list below:
sf.keyboard.press({ keys: 'cmd+s' });
A
+
between two names indicates that the modifier should be held down while pressing the other key.Complete list of key names for use in
sf.keyboard.press
:ctrl cmd shift alt scroll down scroll up mouse button 3 section grave a s d f h g z x c v b q w e r y t 1 2 3 4 6 5 equal 9 7 minus 8 0 right bracket o u left bracket i p l j quote k semicolon backslash comma slash n m period numpad 0 numpad 1 numpad 2 numpad 3 numpad 4 numpad 5 numpad 6 numpad 7 numpad 8 numpad 9 numpad multiply numpad plus numpad minus numpad comma numpad divide numpad equals numpad enter numpad clear f1 f2 f3 f4 f5 f6 f7 f8 f9 f10 f11 f12 f13 f14 f15 f16 f17 f18 f19 F20 command shift caps lock option control right shift right option right control return tab space backspace escape function volume up volume down mute help home page up delete end page down left right down up ⇧ ⌥ ⌃ ⌘ cmd ctl control alt caps enter esc del spc pgup pgdn
Jesper Ankarfeldt @JesperA2021-06-29 12:24:42.736Z
I'm trying to trigger the windows search field on a windows computer that is running in Microsoft Remote Desktop.
So I'm basically just trying to send the command key.When I use
sf.keyboard.press({keys:'cmd' )
orsf.keyboard.press({keys:'command' )
I can't figure out if it's not sending the command or it's just not received on the Remote Desktop.My workaround at the moment is
sf.system.execAppleScript({ script: 'tell application "System Events"\n' + 'key code 55\n' 'end' })
As this is just sending the key code without thinking about apps or anything.
Christian Scheuer @chrscheuer2021-06-29 14:55:15.189Z
sf.keyboard.press
cannot be used to send just the modifier key. I think you might be able to use sf.keyboard.modifiers with cmd set to true, and then to false, instead. (also insert a wait in between)Jesper Ankarfeldt @JesperA2021-06-29 15:18:53.390Z
Cool. Yeah tried that (without the wait earlier, but tried that now as well). But no luck.
There's definitely something going on in terms of what Remote Desktop is sending in to windows.
Using
sf.keyboard.type
also only sends the letter "a", so I have to usesf.keyboard.press
and then just split up the text in order to input text.Christian Scheuer @chrscheuer2021-06-29 15:24:44.888Z
Yea gotcha. Remote Desktop is pretty messy with keyboard commands even without SF, so I can imagine it would be unstable or hard to control from SF as well.
Christian Scheuer @chrscheuer2021-06-29 15:25:42.220Z
It may be better to invoke this through ssh, some kind of remote PowerShell or something like that.
Jesper Ankarfeldt @JesperA2021-06-29 16:55:02.631Z
Yeah was thinking of seeing if AutoHot keys could be controlled from SF over ethernet.
But I think I've got the things I wanted working right now, so that might be for later if things should be more advanced :)
- In reply tochrscheuer⬆:Christian Scheuer @chrscheuer2018-06-17 16:11:22.842Z
To type unicode text, use the
sf.keyboard.type
action.
Use this for cases where a user supplied string of text needs to be input, or anything where a series of characters - not shortcuts - need to be inserted as a value somewhere.Example:
sf.keyboard.type({ text: 'One two three four æøå ÆØÅ ö ü ä and done' });
- JIn reply tochrscheuer⬆:Jonathan Grossman @Jonathan_Grossman
I'm using the type text macro to speed up input of my password when installing something for example.
the macro works when I'm in a program like MAIL but won't work when there is pop up dialog box like when you are installing an app and it asks for your password.
Christian Scheuer @chrscheuer2020-05-13 17:17:46.274Z
Hi Jonathan,
Generally, I would advise very strongly against this type of macro. I would definitely love to have one like this myself, but since your settings are stored in the cloud, storing your password in clear text in a script or macro is not safe.
- JJonathan Grossman @Jonathan_Grossman
ok thanks
- TIn reply tochrscheuer⬆:TJ Forman @TJ_Forman
Not sure why some of these scripts work. And the last one does not. Hopefully someone with more experience can help me out.
**This one works in PT is selects the very next full region to the right. Works Great with Stream Deck! **
sf.keyboard.press({ keys: 'ctrl+tab' });This one works too. Selects the very next full region in PT and then centers it.
sf.keyboard.press({ keys: 'ctrl+tab' });
sf.keyboard.press({ keys: 'right' });**This does not work. It looks like it should based on the syntax of my understanding. I'm fairly new! **
sf.keyboard.press({ keys: 'ctrl+tab+alt' });Christian Scheuer @chrscheuer2023-02-09 04:58:43.105Z
You would need the modifier keys first, ie.
ctrl
andalt
, then followed by the key to presstab
, soctrl+alt+tab
.Note that it's easier to learn how to do this by making a Press Keys macro action and then convert it to a script.
- TTJ Forman @TJ_Forman
Yes! That worked great. Thank you for the support!