How to find the CapsLock indicator via image search?

I want to use Sonoma's CapsLock indicator to locate the position of the caret (text cursor), but I'm having troubles to find the image. How come?

Screenshot 2024-03-31 at 08.04.38


Test - Diacritics.kmmacros (48.4 KB)

This is a total guess, but perhaps the OS is drawing it at a level that Keyboard Maestro can't see it? It's visible to screen captures, and in a test I did with ScreenFlow, but it's definitely not visible to Keyboard Maestro, as my test macro failed, too. @peternlewis might have to chime in on this one.

-rob.

1 Like

BTW: This can indicate that Apple has a way to locate the caret position programmatically…

1 Like

I agree, but I also agree because Apple places the text cursor on the screen, so by that fact alone it must know where the text cursor is.

It's the same thing with OCR. Apple must know "where" it found the word(s), but does not return any data about the words like colour, position, font name, etc.

There is a way to make KM see the CAPS LOCK icon. What you do is use a command line version of the screencapture utility with the parameter "-C" which captures the cursor AND the CAPS LOCK icon. Then you can use the Find Image action to search for the location of the CAPS LOCK icon inside the file, (which it can do!) which should have the same dimensions as the screen. It's probably going to add a second of processing time to save/load the file, but it should work.

1 Like

Sadly, they don't reveal that information in any form I've ever seen that's accessible to a third party.

Creative solution, I like it! And this also probably explains why that image is invisible to Find Image on Screen: It's just a custom cursor, and those aren't visible to the Find Image command.

-rob.

1 Like

Capture the screen using the Screen Capture action and see if the capslock image appears in that captured image.

No, the image does not appear, and the reason for that is that when that action is executed, the image actually visibly disappears from the screen momentarily while the action executes.

Does that happen even if you have released all the keys? That when the screen capture happens the symbol disappears?

Does that happen when you are trying to use the Find Image on Screen action or Found Image condition?

If so, then I guess that is what the system is intending to do and you're probably out of luck.

This action indeeds captures the caps lock icon:


IMAGE

But I don't see how to set the file image.png as target for the search action. Do I have to open it in Preview?

I think I made a mistake. While it's possible to change "the image you are looking for" into a file, it is not possible to change "the image you are searching inside" into a file. I was wrong. Sorry. Of course, you may be able to work around that by opening the image into Preview, displaying the image as a full screen image, and THEN doing the search. Yes, maybe that would work. And you would get full credit for solving it. I'll test it now and see if it works.

It seems that I got your idea (using Preview) working!

image

When this macro runs (I'm using a 15 second periodic trigger to run it) it will take a screencapture (with mouse enabled) then open it in Preview, then set Preview to Full Screen, making sure that certain Preview features are turned off, then capture the location of the CAPS LOCK icon, then close Preview and display the results. You may need to copy some of my techniques because I had to work out some timing and GUI issues to get this to work.

Anyone can point out that this is an "ugly" solution, but it does seem to work.

I don't think the opening "Pause 1 second" action is required. And I don't think my macro handles "failure to find image" gracefully. So you may want to tweak this macro for those purposes.

1 Like

Regarding your first question... when I use the Screen Capture action today, it does capture the CAPS LOCK symbol indicating where the text cursor is. Perhaps I was using a different trigger yesterday.

This means the macro solution I just posted for ALYB could be modified. But since it works, I won't confuse the issue by modifying it.

I had another look at the Find Image action and now I got it working again. It only works when I set the scanning area to whole screen, not if I set it to the front window:
1


I also noticed that the caps lock indicator also is a button: when you click on it, caps lock is toggled off :).

1 Like

I've actually got it working. Try taking less of the image, so you aren't including the rounded corners (they're transparent so any background, including underlying text, could mess up the detection):

image

(And don't forget to cover/hide the macro action's image well when testing -- that catches me out every time!)

1 Like

Now I have stitched everything together:

Great catch. I never thought of that. Anyway, I had fun looking for a workaround.

I guess in a way that makes sense, i.e., that the symbol wouldn't be in the "Front Window" as macOS is probably considering the CAPS LOCK indicator to be in its own window.

Regardless, I had fun coming up with the workaround for you.

1 Like