Move Cursor to Application Center After Command+Tab Activate

I'm try to make a macro to move cursor to the center of the application after a COMMAND+TAB keyboard switching application, but I find when i use mouse click to the other application , it still activate this macro, I dont want to active this macro when using mouse, Because mouse action is a intend behavior and the movement is exact what I want, Is there any way to only trigger this using command+tab ?

Your macro says “any application activates”.

There’s no way that I am aware of for Keyboard Maestro to know if it activated by CMD+TAB or mouse click.

I don't know how to do this only trigger for command + tab, once I set command+tab as a triggring key, the command + tab don't work and can't switch between windows

This worked for me in my testing.

If you trigger a macro on the actual hardware device key and not the keystroke it doesn't seem to interfere with the application switcher in the OS.
Then once the macro is triggered wait until the cmd key is released. Wait .1 seconds for the new application to actually activate, then trigger the mouse move and highlight.

Note because it's triggering on a specific device key, you may need to click where it says USB-HID Keyboard Tab and then type Tab on your own keyboard. If you use multiple keyboards you may need a trigger for each keyboard.

Macro Download:

activate and move to middle.kmmacros (4.0 KB)

1 Like

I think the trick is in how cmd+tab works. You press cmd+tab, then release tab while holding down the cmd. hit tab until the app is selected then release the cmd key.

Basically I trigger when the tab key of cmd tab is released on the keyboard, then wait until the cmd key is released too. Finally I wait for actual application activation and execute the rest.

1 Like

Thank you @kvanh , this works, but there is some new problem,

  1. If I'm pressing command+tab very fast, the OS window can switch between the two most recent apps,but the script didn't active, looks KM cant capture a fast command+tab in my machine(I'm using a external mechanical keyboard)

  2. I'm using a macOS app named context, so I can switch app not only use command+tab but, can select the app in a list with up arrow and down arrow, then press enter and active it .

So I think what I want is : only move curosr when NOT ACTIVE BY MOUSE

Maybe if I can detect whether

  1. if the cursor didnt have any click opeartion(or movement?) in the last 0.1 second ,
  2. there is a window active between,

then I can use that and combine with your script, is there a way to detect that?

Just getting back to looking at the forum.

I can't think of a way to accomplish this. I tried having a macro that triggered on application change checking the mouse button to see if it could catch the mouse button still being down but that doesn't work.

You can't trigger KM on mouse buttons or mouse movement (probably a good thing as it would be triggering A LOT).