Solution: Image occlusion fit to canvas automatically for Windows 10 (AutoHotKey needed)

To make the image you load from your clipboard in image occlusion you can make the image automatically fit to canvas (as long as you use a keyboard shortcut to open it, it is not enough to open the IO-window with your cursor.
Based on pressing the keyboard shortcut a mouse click in the middle-ish of the screen is initiated (with a 1-2 sec delay, depending on how fast or slow your loading time is, as it is not enough that the window opens, the image in the canvas has to fully load before the “Mouse click in center → f” for centering the canvas works.

I have ~^+O:: set to ~^E:: because I changed the Ctrl+Shift+O image occlusion shortcut in the add-on to Ctrl+E

Of course it would be better if there were an option for the add-on to do this automatically itself, but until then, this is an OK temporary solution.

#ifwinactive ahk_exe Anki.exe
;You can increase/decrease this based on how fast your image occlusion window loads
winwait, Add ahk_exe anki.exe,, 0.4
if errorlevel
msgbox, window took too long to open 
;You can increase/decrease this delay based on how fast the image in the canvas loads
sleep, 2500

; ↓ You can edit the X_Pos / Y_Pos values ↓
WindowTitle := "Image Occlusion Enhanced - Add Mode"
;The title of the image occlusion window
                ;note: you can get this title with the Window Spy script/app which should come installed with AHK. 
X_Pos := 800        ;The X position within the window you want to click
Y_Pos := 800        ;The Y position within the window you want to click

WinGet, WindowArray, List, %WindowTitle% 
;max 1 window with the given title
if !(WindowArray = 1)
    msgbox, % "More or less than one window found with the title: " WindowTitle "`Script will close now"
Window_UniqueID := WindowArray1
ControlClick, X%X_Pos% Y%Y_Pos%, ahk_id %Window_UniqueID%,,,, NA  

Text = f
Send %Text% 

Special thanks to ShambleS1980 on the AHK DIscord server. (and me, MedBooster :p)

Thanks for posting this, that’s a clever workaround! If you’re up for giving Anki 2.1.50 a try (not all add-ons are compatible yet, so beware), I just released v1.4.0 of IOE which should fix the auto-canvas-fitting: Image Occlusion Enhanced [Official Support Thread] - #53 by glutanimate

The fix is a bit hacky by necessity and I was only able to test it on a limited number of set-ups so far, so I would be interested to hear if it works for you.

It took a long time before I upgraded my Anki because of Add-ons breaking, but currently (on 2.1.54 qt5) it seems like the add-on does what my Autohotkey script did automatically, which is great!
(It’s good to not have too many scripts running – and it seems to lag less as I don’t have to worry about the script running before the image has loaded fully, though it still lags a bit as I see that the image still loads outside the canvas)

Did you end up using a similar solution where the add-on itself clicks in the middle and also inputs “F”? –– I don’t think so? Because I see that you still have to click on the canvas in order to make “F” work for recentering if you’ve scrolled with your mouse. Interesting… Maybe consider that too? Making it select the canvas as well so that you can use the following shortcuts without clicking on the canvas again?

A – select all
G – Group selection
F – Fit canvas
R – rectangle
S – Select

Now that I see that… I might as well keep my script running just for it to select the center automatically as well… (without the F input of course as the add-on does that automatically now :slight_smile: )

By the way, it seems like the “Path tool” does not work. I am only able to make a single dot, but no shape.