Spacebar Can Act Like Command Key

I'm doing some preliminary testing now.

:+1: ......

I haven't solved it yet, but I'll show you the approach I'm testing. For testing purposes I'm just trying the simple case of emulating autorepeat withe the LEFT ARROW key. The first problem with this routine is that it's recursive, resulting in a failure. That is, the single action in the macro triggers itself. There's probably a way to fix this, but I'm struggling with that at the moment. (Disabling a macro inside a macro is always something that I've struggled with.) The second problem is that the KM engine triggers the autorepeat really fast (it's not using the System Preferences value; it's autorepeating on its own.) That should be easy enough to fix with a timer. Basically, we will implement our own speed controls once this works. The timer may not work as accurately as the System Preferences timer because the KM Engine isn't designed to be a real time OS. The third problem is that we want it to work with about 6 keys. We may be able to do that with a single macro, but if we need six macros, sobeit.

If that helps you. Here what Chris recommended. (autorepeat in System Preferences is OFF), but that does not work with arrow keys :frowning:

I didn't know Chris had been helping you.

If he couldn't get you a full solution, well, I'm not giving up quite yet, but he knows a lot more than me. So my chance of success is only about 30% now. Still, I'm intrigued by this problem. I haven't give up yet. But I may need some breakfast.

Do you have an external USB device like a StreamDeck? We could probably get it to work if you used keys on that device instead of the keyboard. But I understand that's not what you want.

I think the main problem is that MacOS gets confused when you get both the keyboard pressing a key and KM sending the key at the same time. It causes MacOS to think that the physical key is "up" when it's actually "down" (because KM intervened and got MacOS confused.) However I have a "way outside the box idea" that may help. I'm still pondering it.

I appreciate you trying anyway. And no, I do not have a StreamDeck. Wouldn't it be easier to just change the behavior of the spacebar after all? But I don't care about having 6 macros. It's the result that counts :slight_smile:

Do you have one of those small laptop keyboards or one of those extra large keyboards that you usually get with desktops (ie, the extra numeric pad section)?

Just a normal laptop keyboard, no numeric pad.

That's too bad. We could have solved most of your problem by using the numeric keypad as your "arrow keys". Of course, that's not exactly what you wanted, but I think it could have worked. We could have used them to receive keys without confusing MacOS when we sent out keys.

I'm not out of ideas yet, though. One of my trade secrets is being familiar with MacOS's accessibility modes. That can sometimes be used to redefine the keyboard and mouse in surprising ways.

No problem, Sleepy. Thank you very much anyway. My solution was and remains: "autorepeat in System Preferences OFF". Then the spacebar behaves as I want. And for Enter and other keys I have to press repeatedly. I was just hoping that someone knows a solution...

I just discovered something curious. There's a feature in Accessibility that lets you turn on sounds effects when you press a key, and when you enable that, you can hear that autorepeat is actually "on" when you hold down the A key, even though we both thought it was "off". So it's actually only half-off. You can hear it's being activated, but it actually isn't sending out the key. That's very curious. These are the kinds of surprises you get when you experiment with Accessibility mode.

I can't believe it! I think I got it working! Don't wake me up! The trick was not to trigger on the hotkey, but instead to trigger on the USB Device Key, as shown in the image below.

So for example, this code will autorepeat the right arrow key even when the System Preferences autorepeat feature is turned off:

I'm going to reward myself with a break now. But I think this is the key to the whole puzzle. As I said earlier, I think there's a way to write this all in a single macro rather than one macro for each key, but it won't really be any "shorter" that way, so if you want to test this out with six different macros, go ahead.

As I said earlier, this may autorepeat too fast for you, but we could slow that down with a little code, I think.

Yessssss, it works for all the keys I need it! But as you say, it's too fast, when pressed an hold. And for example, if you press the arrow key only once, the cursor makes two steps. It would be great if you could do some more fine tuning. But take your time :slight_smile: Thank you, Sleepy!

I'm happy that you are happy (IHTYAH.)

Fixing the timing shouldn't be a problem. But there's a small catch. KM triggers this macro quite quickly. Very quickly. In fact, so quickly that I'm not sure if it can trigger multiple copies at the same time before the previous one finishes. That's not a serious problem, but I can tell you that if you don't write code that finishes quickly, the KM engine will crash because the KM engine can handle only 50 running macros at a time. Any more than that and the Engine stops all macros. But I don't think we will be anywhere near that limit.

It seems to me that the way to solve this problem is to use a semaphore at the top of each macro, with a unique name, then insert your key as you do now, then insert a Pause statement of a certain duration as your third action of each macro. The semaphore needs to abort immediately if there's another copy running. Your pause statement could be a constant like 0.1, or even better, you could pause for a variable number of seconds, and you need to use a global variable with a name something like, "AutorepeatPause." Make sure you set that global variable to something valid. Try 0.1 for starters, which sets the speed. I don't know what speed you will like.

So it should look something like this:

If you have any other problems, or if this doesn't work, let me know. To be honest, I didn't test it, because I do this sort of thing so much, I'm pretty sure it will work without me testing it. I know that's unprofessional, but you get what you pay for.

Did I neglect to mention that your semaphore needs to turn off error reporting. It should look like this:

Sorry, what kind of Pause is that? Could you post the macro? That would be nice :slight_smile:

I am doing something wrong, but I don't know what :frowning:

The first mistake I see is that you didn't assign a value to the AutorepeatPause global variable. I mentioned this when I wrote "Make sure you set that global variable to something valid. Try 0.1 for starters". You have to set the value in some other macro that's unrelated to these macros.

If that doesn't fix your problem, let me know.

The reason I didn't post the macro is because, as I said, I didn't test it.

It's just the standard Pause action in KM. It may not look that way because KM edits the title of actions. but it's just a basic Pause action. I suspect you understand that now, or am I wrong?

Do not worry, I'll test it and then report back to you. With your macro I can figure out how you built it. I really have little idea and would be glad for the macro :slight_smile:

Ok, I'll test it and post it. Give me a moment. Here it is. Keep in mind you still have to heed my advice and set the value of the global AutorepeatPause variable using some other method. I tested it and found that 0.1 runs a little faster than you might want, so maybe 0.2 will be better.

Autorepeat Right Macro (v10.0.2)

Autorepeat Right.kmmacros (3.3 KB)