Some typing / key pressing issues with and without modifiers

Hey guys,
I still have some problems using typing-related tasks.
a) using custom-duration holded modifiers:
I simply want to perform the following task:
In ProTools (audio workstation) I want to select an area that lies between two location markers in a timeline. What I need to do is:

Press the keys: comma-7-comma on the numpad, then hold Shift and then while keeping holding Shift press/type comma-8-comma.
Bildschirmfoto 2022-04-28 um 22.14.29

This doesn't work. It seems to be that the holding of the shift key is being ignored. I already tried the same macro inserted 1 sec pauses after actions #3,#4 and #7 without success....
Since I wasn't able to perform this general task pattern (hold modifier x, do some action or typing and release modifier x) so far at all I'd be happy to hear what I'm doing wrong here....

b) I want to perform some single key shortcuts in a row - just like the three first actions in the macro above (comma-7-comma). I've tried to do that using the "Insert Text by Typing" action instead which didn't work....is there any way of grouping consecutive single key presses in one action ? Would save a lot of "building blocks" and hence screen space in a macro....

c) Is it possible to adjust the typing speed of "Insert text by typing" ?

Thanks !

Is there a reason you can't do this?

If the particular thing you're trying to do requires that the modifier be held throughout, you can do this:

...or this:

1 Like

As well as the press and hold for the Shift key, each Type a Keystroke action in the second batch needs to have the shift key. So:

  • Press and Hold Shift
  • Type Shift-,
  • Type Shift-Numpad-8
  • Type Shift-,
  • Release Shift

Hey Peter,
really....? Uhm.....just for asking.....what purpose does a "hold modifier" action have at all when I need to add the exact same modifier to any key I want to press (edit: having pressed virtually through KM) during that time of (obviously not-)holding the modifier...? :thinking: :thinking: :thinking:
And why does this work with Applescript (thanks, Noisneil!) instead of the KM action that should be processing this task?
Seems pretty laborious for me....

Update:

Also tested this completely without the holding modifier lines, only using

instead. That also works - in this case (!)
But in case I'd want to perform other actions with modifiers being held down for longer, lets say also including alt-mouse clicking somewhere on the screen....? So again my question to Peter....what does the action "Press and Hold Shift" do if it doesn't do what it's supposed to do ? :exploding_head:

Lets look at a slightly simplified case:

  • Type Shift-X
  • Type Shift-X

Produces the sequence:

  • Press Shift
  • Press X with shift key modifier set
  • Release X with shift key modifier set
  • Release Shift
  • Press Shift
  • Press X with shift key modifier set
  • Release X with shift key modifier set
  • Release Shift

Compare that with:

  • Press and Hold Shift
  • Type Shift-X
  • Type Shift-X
  • Release Shift

Which produces:

  • Press X with shift key modifier set
  • Release X with shift key modifier set
  • Press X with shift key modifier set
  • Release X with shift key modifier set
  • Release Shift

In almost every case, this will result in no change.

However in some apps, eg where holding the shift key down produces some modal change, then it will result in different behaviour.

In that case, the app does not really care about the shift key being held down, and it just looks at each key in turn and the modifiers associated with this, and so the simple sequence is exactly what you would normally use.

The Press and Hold Shift keeps the shift key pressed for the duration. However if you explicitly type a keystroke without the shift key (including via Insert Text by Typing action with lowercase letters for example), the shift key will be released to type the character and then re-pressed.

Press and Hold Shift is about the behaviour of the shift key while nothing else is happening - it does not override the behaviour of other actions and their use of the shift key.

Also note that virtual and physical keys are not interchangeable, so if you use the Press and Hold Shift action, and it was still in effect when you pressed the “X” key on the keyboard, you would get a lowercase “x”.

3 Likes

In before "So why does the action display a 'G' when it types a 'g' then"...

Blame Apple, blame Microsoft -- Cmd-N and Ctrl-N are actually Cmd-n and Ctrl-n, when you think about it. Specifically for us, blame Apple's HI and Documention Guidelines, which say you must use uppercase when referring to letter keys to be (or which have been) pressed.

AppleScript's System Events behaves differently, as you've seen -- I guess it acts at a different "level" in the Events chain. But while different scripting/programming systems may behave differently, there's always a pattern for that particular one, and you just have to go with it. If you get caught out by KM, simply log the "output" in some way, eg by directing your keypress sequence to TextEdit instead of your target app, and that should give you a clue as to what is happening.

Again....maybe it's just me not seeing the forest for the trees....but: What sense does it make then at all providing a "hold modifier" function like that?
Why on earth should I use a modifier for having it being held down only for itself ????
And this statement of yours is very very strange once you really read it consciously:

ok. fine. That's what I expect it to do. But then:

Yes. That's exactly what I want to do with such a function!

Uhm......what ? Again. I use a function that should hold a modifier. And then it stops being held down just for the duration of any another action that happens in the meantime and then resumes??? Sorry, but that is insane. Could you please tell me then what kind of application I could even imagine using the function at all ?

The example we already had (holding Shift, pressing some keys and then letting Shift go) obviously doesn't need or doesn't fit the application of the modifier function - as discussed. So what it's used for then ?

Sorry for appearing being offending - that's not my intention at all....just can't see any sense in all that - and honestly: Spending so much time for realising such simple tasks just makes me a little indignant.... :no_mouth:

Imagine an application that has a scrolling image on the screen. Imagine that it creates a dot on an image every time you press a “x”. Imagine that application, if you hold the shift key down and press an “x”, and then keep the shift down press “x” again, it draws a line instead of two dots. But if you press shift-X and then release shift and then press shift-X it just creates two dots.

So you need to simulate creating a line in the macro.

So you need to simulate pressing and holding the shift key, and type shift-X twice and then release the shift key.

That is the use of this action.

  • Press and Hold Shift
  • Press Shift-X
  • Pause
  • Press Shift-X
  • Release Shift

It is not some sort of shorthand for “all the actions after this should just assume the shift key is down rather than typing the keys that are specified”.

Lots of applications use modifiers by themselves to affect behaviour. Imagine the same application above, but it just draws a line while you hold the shift key down (the “x” key no longer being involved). The macro might simply be:

  • Press and Hold Shift
  • Pause
  • Release Shift

In any event, the simple rule is:

  1. Use the appropriate modifiers in the actions you use.
  2. Use Press & Hold Modifier only if you actually need the modifier to be simulated as down for a period of time or a set of actions (such actions of which should still follow rule 1).
1 Like

Thanks Peter for your detailed explanations. At least now I understand the fine distinctions that are underlying this whole modifier topic in KM.

Coming from other software I might take some time to get used to the way of thinking setting up macros in KM seems to require...which doesn't always feel straightforward - at least for me....

Could you tell me something about my questions parts b) and c) of my initial post ?
Help appreciated !

@uliauer

b) I already covered that. It's not hard to add three Simulate Keystroke actions, and they can be collapsed (or grouped and then collapsed) if you don't like how much space they're taking up (see gif below). If for some reason you must have everything in one action, AppleScript will do that.
c) To be clear, Insert Text by Typing will not result in keystrokes being recognised as shortcuts. However, if you do actually want to type something a little slower, have a look at this post by @ccstone.

Group and collapse actions:
ScreenFlow

I'm using a small macro to group the actions:

Group Actions.kmmacros (28 KB)

Screenshot

1 Like

And to chuck another option in, I guess (though I haven't tried!) that you could create your "set of keystrokes" as a separate action and call that as a subroutine from your "main". Might be useful if you're repeating the same steps in multiple "main" actions.

1 Like

I'll confess, I'm also finding it hard to get into the "KM mindset". What's helping me is:

  • Forgetting how I've done things before -- in many cases those methods are no longer available to anyone (eg Apple's "removal" of kernel extensions)
  • Trying to understand other people's macros -- step by step, with the manual at hand
  • Trying to answer other people's questions without looking at subsequent answers (even if I don't post a reply) -- looking at a problem that isn't "mine" lets me start with a clean sheet, with no preconceptions of how I've done it "in the good old days" :wink:

Above all, get in there and play. IMO, nothing helps you learn new software better than getting stuck in and giving it a good kicking!

2 Likes

And it might just be worth repeating (as @noisneil has already mentioned this) that it is easy to rename that enclosing Group Action and you can then treat it like a single Action and even copy and paste it to different parts of the Macro.

Grouped:

And that Group Action renamed to something that you can see at a glance:

And... That renamed Group Action can be saved as a Favorite Action so that you can use it again in other Macros (even if you only use it as a kind of template and change the keys it is pressing).

Select the renamed Group Action and from the Menu, Actions>Add to Favorites

3 Likes

Thanks everybody for your time and efforts.

Yes. Indeed it is not very straightforward. The "Grouping" idea is good to have but it only saves screen space and not programming time - sorry, but I'm kind of a nerd in terms of time and work efficiency...but I know that KM has some shortcomings in these aspects (thanks Nige_S for showing that you agree) so I have to deal with it as is.

Again @ Peter and all:
Still struggling big time with my application of holding alt(=option) problem:

What I want to to is as follows:
I want to make a key on my USB X-Keys device to just operate like the alt key and another key as the Tab key for the purpose of alt-tab-stepping through the apps and windows in Win11 on Parallels - just like you would do on the native Mac using command instead of alt(option).
None of the variants Peter has named so far in this discussion works.
I've set up the macro like this (referring to a method I've learned in another thread for mouse-jumping to a certain screen location during holding a key and then move back to the original location on release):

Should that for itself work like intended ? (unfortunately we can't see whether alt is hold or not, but in Debugger it is shown that the action is taking place (first line appears on pressing and holding, second line on release after a while):

Now the problem:
The other key on the USB device should now emulate the Tab key being pressed several times, also with some pauses in between in order to select an app / a window in Parallels. The simple macro for the other key goes (or at least in my mind should go) like this:

Doesn't work. Also tried to use "alt-Tab" instead of Tab only in the action - according to Peter's explanations...this leads to the same result like pressing alt-Tab once (directly switching to the last app/window)...

Any clue how I can get to what I want here ?

Please don't put words into my mouth -- that is not what I said.

That I'm having trouble getting into the "KM mindset" is because I'm used to writing scripts that do things rather than macros that control other things. It's no reflection on KM, it's me trying to use KM's screwdrivers in the same way as my AppleScript spanners.

And I'll say again that sending the Alt-Tab event from KM, using a simple "Type the Option-Tab Keystroke" action, worked 100% for me once I'd changed my VM settings as discussed in the other thread. I'd argue that it isn't the events that KM is sending that are the problem, but the way Parallels is interpreting/redirecting those events.

1 Like

Compared to what? Is there another piece of software you know of that does it a different, more efficient way?

It takes me about 3 seconds to enter a Simulate Hotkey action. I can then duplicate that 5 times in about 1 second, then go through and change the hotkeys. From there it takes about 2 seconds to group and collapse them. I think this is just a teething problem, and you'll soon be flying along.

On to your macro...

It's best to actually post your macro rather than just screenshots, as it means we can try to help by editing what you already have. That said...

No, for reasons stated earlier in this thread.


X- Keys - Hold Alt.kmmacros (23 KB)

Macro screenshot

This uses AppleScript, so it takes a fraction of a second for ⌥ to be held down. Just be aware of that. Replace the USB Device Key trigger with your own, remembering to include the ⌥ modifier for the release trigger.
Keyboard_Maestro_Editor_—_X-Keys-_Hold_Alt


Yes, because that's what your macro does. If you want it to repeat the Tab press with pauses, you need something like this. Remember to change the trigger, obviously.

X- Keys - Tab x 3.kmmacros (21 KB)

Macro screenshot


The above macros hold ⌥ and simulate Tab separately. I don't know why you want to do this.

Here's one that does both together, which seems the logical thing to do, unless you have a good reason not to. Again, remember to change the trigger.

X- Keys - ⌥Tab x 3.kmmacros (21 KB)

Macro screenshot

Sorry, was not intended....obviously got you wrong here...and of course I didn't know about your general use of scripts as a workflow...:wink:

Hm. I made a screenshot of the whole macro. What do you mean instead...? Am I supposed to export another view or data of the macro ?

I knew this was hard to understand :wink:
Just to make that a little clearer: I don't want KM to press Tab several times with pauses in between, I want hold the one hardware key to hold alt and then I want to use the other hardware key to use it as a Tab key and tab through with whichever pauses I want to....

I've tried to follow the steps you kindly provided, of course replacing your Stream Deck key by my own but still can't get it to wrk with the second key as the "forwarded" Tab key.....can you do that on your Stream Deck setup ? Maybe you could provide me with the macros I'm supposed to use for the two keys ? And in order to exclude transferring issues from Mac OS to Parallels at first, could you set this up simply with CMD-TAB for me so that I can try it with Mac OS's app-toggling ?

It's always helpful to post the macro itself.

File > Export > Export Macros.

As you read on, you'll notice that I wrote the remainder of this post before I saw your reply. Regardless, you can adjust the actions each key combo performs to suit your needs. In this case, you'd just simulate ⌥Tab.


It crossed my mind that you might be insisting on holding one key while you press another because you want different held keys to make the same trigger do different things.

For example:

Press key A, = Tab
Hold key 1, press key A = ⌥Tab
Hold key 2, press key A = ⌘Tab
Hold key 3, press key A = ⇧ Tab

That's the only reason I could think that someone might want to do that rather than simulate hotkeys with their own modifiers.

In the macros below, I've used hotkey triggers for clarity, but you'll replace them with USB Device Key triggers. Leave the macros disabled until your triggers are set up.


X-Keys Hold.kmmacros (23 KB)

Macro screenshot

Replace the Hotkey triggers with the USB Device Key triggers that you'd like to hold in order to make another key do different things. Enable this macro and the red action and press one of the keys. You'll see its TriggerValue appear in a window. Copy this, ready to paste into the second macro below. (Disable the red action again until you want to get another hold key TriggerValue.)


X- Keys - A-B-C Switch for Held Keys.kmmacros (48 KB)

Macro screenshot

Open up one of the "Do different things when different keys are held" groups and paste the previously copied TriggerValue into one of its Switch fields.

Switch Fields Screenshot

Repeat until you've set up all the hold keys you'd like and then adjust the red actions to do whatever you'd like them to. Set the triggers to the USB Device Keys you intend to press (while another is held), enable the macro and away you go...