My bad -- I was concentrating on the pause action, assuming you had the branching already.
There's (at least!) two ways of doing this. The obvious way is to grab the millisecond time just before the pause action and just after -- if the difference is less than 2000 then a key was pressed, otherwise it was a timeout. But that could leave you at the mercy of timing issues around the 2 second mark.
IMO a better way (unless you need the time!) is to use the fact that a timeout can abort the macro. If you just want to cancel, leave "Timeout Aborts Macro" turned on and "Notification" off:
If you want to continue rather than abort, perhaps to do some cleanup, and so need different branches depending on whether or not a key was pressed -- do the same but catch the error with a "Try/Catch" block. The logic would be that "no error means a key was pressed":
For now, thank you @Nige_S@ccstone very warmly for your support. I need some time to try it all out. After that I will get back to you with the result ... and tell you what this is all about, if anyone is interested
Unfortunately, none of the macros work. Whether I just press "f" or "f" and immediately afterwards another letter both lead to the same result. Does this mean that it might not be possible?
Probably -- I'm confusing myself now! But the important bit is the ability to branch depending on keypress or timeout, and @Frankb can do it whichever way round is required.
I'm not sure understand me either! I'm very much learning as I go on this, so apologies if I'm sowing confusion...
There are reasons we're advised to use chords rather than unmodified keystrokes as hotkey triggers. And the workarounds to solve those problems will make the macro less reliable. the pressed keys change includes key release, so you need a pause between trigger and state check else releasing the trigger key will cancel the macro -- make that pause too short and you'll cancel the macro when you don't mean to, make it too long and it won't register the next keypress if you're a fast typist.
Also note that "ss" is quite a common combo to type -- and if "s" is your hotkey that will trigger the macro twice rather than trigger then cancel! So we need a semaphore lock with a very short timeout so any new instance aborts (rather than being added to the FIFO queue) if the macro is already running.
(I didn't know about that until trying this out, so I've certainly learn something today -- thanks!)
The following seems to do what you want, at least when used with "sharp and deliberate" keypresses -- you'll have to find out for yourself under real world conditions. I've kept the "Try/Catch" format because that makes the logic explicit and easier to follow.
Good morning @Nige_S In any case, it's morning where I am.
Thank you so much that you dedicate your time to me. You are my hero anyway. And I'm really sorry if I'm wasting your time on something that is not solvable, maybe. But your macro doesn't do what I want it to do.
A simple test:
just type "s". Safari will open. That is correct.
Type "s + space". Safari will also open. But it should not. because another character (space) comes after the โsโ. The pressed key change.
That's probably what you explained to me. This macro is only about time, not about key change.
When I write "simplicity" Safari is not opened. That is correct. But not because the first letter โsโ is followed by another 9 characters, but because too much time passes between the first letter โsโ and the last letter โyโ.
Those both work as requested for me. But you have to be deliberate -- try "s"then wait a second then space. I think you're typing to quickly...
You must have a delay after the trigger and before the "Pause Until..." action so that the trigger's release is ignored. But any character typed during that delay will be ignored -- I think you are typing the space too soon. And when you type "simplicity" you might type fast enough to skip the first couple of characters, but at some stage you'll hit a key after the delay but before the timeout -- if you use my macro as provided you should get interrupted by the "Display Text" timeout message before you complete the word.
So the macro is about both keypress change and time.
IMO, the requirement to use an unmodified keystroke as a trigger is a fundamental flaw -- you might be able to get it to work some, even most, of the time by setting the timings to suit your typing speed but it will fail often. And as you're obviously a proficient typist I can't see why you'd find it more efficient to type an "s" and wait two seconds for Safari rather than type eg โS and have it appear instantly.
But that's probably me applying my own prejudices -- perhaps if you can explain why you need to trigger with an unmodified keystroke rather than the "recommended" method someone will be come up with a different approach.
@Nige_S Yes, it's all about writing fast, keeping your fingers on the keyboard and your eyes on the screen.
If all I have to do is type "s" and I can get two actions out ("s" and open Safari) then everything I described above is fulfilled.
But if I have to type โs, then it doesn't. I admit this is a luxury problem.
My original idea was to work around the usual short/long press macro. They don't work when you type fast because the letters are typed when released, not when pressed. This leads to the problem that not "simplicityโis typed, but โismplicityโ. โsโ is typed on release, while "i" when pressed. With โmy systemโ, letters would be typed when pressed. This avoids glitches when typing fast.
But well, it doesn't work. I'll experiment some more with "the mouse moves". This is almost equivalent.
Just coming at this from a different angle - it seems that you are trying to come up with a system where you can launch Safari during normal typing of text. And you type fast and accurately. You don't want to have to use a modifier key or touch the trackpad - you want to just type stuff and depending on your typing Safari launches or not?
Since you are inventing your own coded system anyway why not just use a Typed String Trigger to launch Safari?
If say you used "sqq" as the trigger that would allow you to choose to launch Safari at any time in your normal typing by just typing "q" twice after an "s" and the "sqq" would not appear in your typed text as Keyboard Maestro handles deleting the typed string.
The reason for the "qq" being that no words (as far as I know) have a double q in them. But there are other letters that could work too.
That's a very good suggestion @Zabobon. At the moment, that's exactly how I do it. My "qq" is "space,space" being that no words have a double space in them or at the end. And because that is even faster.
Unfortunately KM does not measure the time for such triggers. If a word ends in "s + space", I think about something for a moment and then accidentally type space again, the macro "open Safari" is triggered (this is just a sample).
The macro should only trigger if "s+space+space" is typed within one second.
Again I admit, this is a luxury problem
PS: But I still find it surprising that KM can not do something so simple: Do something when nothing happens, after typing a letter.