KM: Macro seems stumped with CTRL-modifier commands in Microsoft Remote Desktop

Hi everyone, I have searched the web high & low for a solution.

Background: I am using Keyboard Maestro (1) to try to make macro(s) for use in an EMR (EG Clinea) in a virtual Windows environment with Microsoft Remote Desktop (MRD). I need to use the "INSERT" key a lot in the EMR, so have used Karabiner to convert "right_command" to "INSERT" key.
KM seems to accept this and shows "right_command" as "Help/Insert"

**PROBLEM: In KM I've made a macro that is not working correctly.
It seems to stop after the first action (ENTER).
CTRL-R (to go to prescriptions) does not happen.
The ALT modifier seems to work. However, text strings are then not inserted where they were supposed to go.
Sidenote: Whilst using Elgato Stream Deck as a launcher of KM macros - it also inserted a great many "aaaaaaaa" in the text string on its own accord, which has dumbfounded me.
I also tried the "record" feature with KM in the background and Remote Desktop app as frontmost... everything recorded nicely, but still not working.

Any suggestions?

(1) Right now without Elgato Stream Deck XL with MacOS Ventura 13.4.1, but planning to implement this later, once I've wrangled KM :slight_smile:

1 Scabies epi COMPLETE.kmmacros (12 KB)

I do a similar thing to access my EMR (different than yours) using Microsoft Remote Desktop (MRD) and I also use the Elgato Streamdeck to trigger KM Macros. The work-around that I have found to work best is to substitute the keypresses that don't work natively with the Execute AppleScript action.

For example, when trying to type: "(Sample-Text)" using the "Insert Text action by typing" you will instead see "9sample-text0" where the parentheses are typed as 9 and 0 and no capital letters are typed because the Insert Text action does not properly convey the Shift Key to the windows computer via MRD.

Instead try setting the text you want to type to a KM Variable (which for this example we'll call: YourText) and then use an Execute AppleScript Action with the following code:

tell application "Keyboard Maestro Engine" to set text2Type to getvariable "YourText"
tell application "System Events" to keystroke text2Type

I can't tell you why this works or why the Insert Text Action does not properly convey some modifier keys to Windows across the MRD interface, but this is the only way I have found to work for me. Perhaps @peternlewis knows why?

For single key presses like CTRL-R that you report not working...again try the "Execute AppleScript" action with code like this:

tell application "System Events" to keystroke "r" using control down

you can use multiple modifier keys like so:

tell application "System Events" to keystroke "r" using {control down, shift down}

You can also use key codes. So CTRL-R would be:

tell application "System Events" to key code 15 using control down

For reference try these links:
Key Code Reference
System Events, Key Codes, and Keystroke
And this free app that will tell you what the key code is when you press a key:
Many Tricks: Key Codes App

Hope that works for you!

1 Like

I have found that sending any kind of simulated modifiers through remote desktops may not work.

I wish I knew why, but there is no way for me to figure it out.

As @maxnnina notes, using AppleScript might work, since Apple has more control than I do.

1 Like

Thank you so much! I'll try!
Ugh though! I was hoping to avoid too many work-arounds using KM.
And weird that MRD does not receive the input when simulated by KM/Elgato or whichever, but works fine when "real" keypresses are performed.

I'll try my hand at your solution and report back if everything is working properly.

Best regards
JD

The other thing that may help you is to put short pauses between each keystroke action. You'll have to experiment but 0.3 to 0.5 second pauses usually work for me...but it will depend on your connection speed to the remote computer. Otherwise KM will execute the steps too fast for your remote computer to respond and the macro will fail.