Please Help Customize a Macro

With the kind help of Zabobon, I created the macro below. I have tried to make a change but have not succeeded.

At the moment the macro does the following.

  • Press and hold "space" for 1 s (or longer) opens a palette. Release "space", the palette disappears. (Space ist not typed)

  • Press and release "space" (in less than 1 s), "space" is typed.

This is perfect for other keys, but not for the spacebar.

What I I would like is that "space" is always typed (when the spacebar is pressed, on key down), even if I hold "space" down and the palette appears.

Can anyone help? Thank you very much!

I suppose it needs something like this. But I don't know how to do it. :man_shrugging:

(1) Type "space", if key down/up within x seconds, abort macro.

(2) Type "space", if key not up in x seconds, show palette.

Do you try just moving the "Type a Space" action out of the second "If" block and up to the "execute" section of the first "If"?

Edit to add:
Also, consider changing that first test. You don't really want to test the current state, you want to test the trigger that fired the macro. So something like:

It may not make any practical difference, but it makes more logical sense.

There's more refactoring to be done -- I don't think you don't need to pause 0.1s on a key release, for example -- but let's get it working first!

Hi Nige, I honestly don't understand what you mean and I don't see your screenshot, I just see a gray area. If you have time, I would be very grateful for a finished macro. Only if you can.

I would normally do this with BTT, but there has been a bug there for years that prevents this from working.

As you didn't post your macro and I'm too lazy to recreate it, here's my take:

Hold Space Bar for Palette.kmmacros (46 KB)

Macro screenshot

The trouble is, if you hold the space bar too long, it starts to repeat (if you have that option on in macOS prefs) and the palette disappears.

What if you don't want a space to be typed every time you call a palette? It would play media or type errant spaces. Presumably, you're only using this in an app where this isn't an issue...?

Thank you @noisneil I put my palette in your macro, but unfortunately it doesn't appear. And you are right, space always repeats itself, hmm. Is there no way to type space only once? ... I could try to disable key repeat in macos.

Ah, how do I post a macro? :joy:

I'll delete that then. The important thing is that "space" is typed when the key is pressed, not when it is released. You know the reason for this :wink:

Works for me. :man_shrugging:t2:

Yes, or just extend the delay before key repeat.

Just drag an exported macro to the comment field and it will be uploaded.

Kurz.kmmacros (6.0 KB)

Ah, ok, that's easy :grinning:

1 Like

This is the bit I'm struggling with. @Frankb, have you turned off "Key repeat" in System Preferences/Settings? If not, I'm not sure you can do what you want.

Yes, but the palette does not appear. Is that correct?

If you've turned off "Key Repeat" then try this:

Palettes and Spaces.kmmacros (3.9 KB)

Image

Yeah that looks right. Odd that it works for me and not you. Sorry, I don't know why.

Great, that works perfectly. Many thanks @Nige_S

@noisneil , you certainly don't have to sorry. I am always very grateful for your help.

One more question, where/how will I notice (in the negative sense) that I turned off the key repeat .... except that the macro works.

Edit // If I may be impertinent.... what if the "space" would be deleted, only it the palette opens. Like with string triggers?

Ahhh, that seems to work.

System Preferences/Settings -> Keyboard, "Key repeat rate" will be set to "Off". Or if you mean "what does turning it off change" -- holding down a key will no longer repeat. That's not such a thing these days, now that holding down eg the E key brings up the "accented characters" box rather than typing eeeeeeeee, but it'll really depend on your personal settings.

Rather than type it then delete it, just move the "Type a Space" from the top into the "otherwise" section of the "If" action -- then it will only be typed when the palette doesn't appear:

Palettes and Spaces v2.kmmacros (3.9 KB)

Image

Thanks Nige, in V2 "space" is typed when the key is released. Unfortunately this does not work for me. I write too fast, that leads to character twists.

But the "delete" solution is good enough for me. Thanks again to both of you.

Edit // In fact, there is one key where I need the key repeat ... Delete. I thought I could solve it this way, but it doesn't work. I'll see if BTT can do it.

Was forgetting that. I was allowing for slow typers (like me!), who could have problems when doing it your way. What works for you works for you -- go for it!

That'll only trigger once when the key is pressed, doing one delete -- you want to do a delete then repeat until the key is released. Set the pause to match your preferred repeat rate:

Repeat Delete.kmmacros (2.5 KB)

Image

This works great, thanks Nige.

Although once more I don't understand why this doesn't work with the trigger.

image

When then in the macro exactly the same is done.

image

Never mind, the main thing is that it works. :slightly_smiling_face:

KM macros are triggered by events -- in this case, the "key down" event for the Delete key. The event is fired once, when the thing happens, so when you press the Delete key down the macro triggers -- it doesn't keep triggering if you hold the key down.

What a load of nonsense I talk! As @Frankb has pointed out, that would be true for the "key pressed" trigger, but "key down" should trigger the macro repeatedly.

But the Conditional checks the state of the key -- "is the Delete key down?" -- and the "While" repeats for as long as the condition is true, sending the simulated Delete once every loop.

So while the wording in your screenshots is similar, the way they are read is different -- "when the Delete key goes from up to down" versus "while the Delete key is down".

More nonsense!

The other way to keep the two straight in your head is that events are things that KM is told about -- "The Delete key has been pressed down" -- while states are things that KM asks about -- "Is the Delete key still pressed down?".

1 Like

I'm sure it's just me not understanding why the macro below works. It works even if in macos the repeat function is disabled. So if I press and hold "j" the cursor moves continuously to the left. On the other hand, if I change the trigger from "is down" to "is pressed", then the cursor moves only once.

With my limited logical capabilities, I assumed one could generalize this behavior.

Edit // by the way, the reverse also works. Macos key repeat on

-> "is pressed" cursor moves only once.

-> "is down" cursor moves constantly.