Chrome Get Zoom %

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
martipe1
Posts: 40
Joined: 05 Apr 2018, 10:42

Chrome Get Zoom %

Post by martipe1 » 27 Sep 2022, 17:16

I would like to know how can I get the zoom in a given tab of Chrome in order to use the right picture with FindClick function.

Thanks

skyth540
Posts: 72
Joined: 24 Aug 2022, 10:07

Re: Chrome Get Zoom %

Post by skyth540 » 28 Sep 2022, 17:32

martipe1 wrote:
27 Sep 2022, 17:16
I would like to know how can I get the zoom in a given tab of Chrome in order to use the right picture with FindClick function.

Thanks

you could either reset with ctrl + 0, or use a more advanced image / pixel search

AHKStudent
Posts: 1472
Joined: 05 May 2018, 12:23

Re: Chrome Get Zoom %

Post by AHKStudent » 28 Sep 2022, 22:46

martipe1 wrote:
27 Sep 2022, 17:16
I would like to know how can I get the zoom in a given tab of Chrome in order to use the right picture with FindClick function.

Thanks
What is your goal? UI automation might be a good choice but would need to know what you are trying to do, if it's to reset, the other reply is perfect

malcev
Posts: 1769
Joined: 12 Aug 2014, 12:37

Re: Chrome Get Zoom %

Post by malcev » 28 Sep 2022, 23:22

In javascript:

Code: Select all

window.devicePixelRatio * 100

BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Chrome Get Zoom %

Post by BoBo » 29 Sep 2022, 00:42

…but would need to know what you are trying to do
Probably creating a set of images that could be used to use ImageSearch under different zoom factors? :think:

martipe1
Posts: 40
Joined: 05 Apr 2018, 10:42

Re: Chrome Get Zoom %

Post by martipe1 » 09 Oct 2022, 19:18

AHKStudent wrote:
28 Sep 2022, 22:46

What is your goal? UI automation might be a good choice but would need to know what you are trying to do, if it's to reset, the other reply is perfect
My goal is to search for a picture, but the picture changes depending on the zoom level, my idea would be to have different pictures (zoom %), and depending on the zoom use the corresponding picture, unless you have a better idea.

Thanks

AHKStudent
Posts: 1472
Joined: 05 May 2018, 12:23

Re: Chrome Get Zoom %

Post by AHKStudent » 10 Oct 2022, 10:39

martipe1 wrote:
09 Oct 2022, 19:18
AHKStudent wrote:
28 Sep 2022, 22:46

What is your goal? UI automation might be a good choice but would need to know what you are trying to do, if it's to reset, the other reply is perfect
My goal is to search for a picture, but the picture changes depending on the zoom level, my idea would be to have different pictures (zoom %), and depending on the zoom use the corresponding picture, unless you have a better idea.

Thanks
are you looking to click that picture? there might be a way to do that without image search by using javascript in the browser address bar

skyth540
Posts: 72
Joined: 24 Aug 2022, 10:07

Re: Chrome Get Zoom %

Post by skyth540 » 10 Oct 2022, 11:00

this could help


viewtopic.php?t=17220

Descolada
Posts: 1123
Joined: 23 Dec 2021, 02:30

Re: Chrome Get Zoom %

Post by Descolada » 10 Oct 2022, 11:05

Solution using UIAutomation:

Code: Select all

#Include <UIA_Interface>

wExe := "ahk_exe chrome.exe"
UIA := UIA_Interface()
WinActivate, %wExe%
WinWaitActive, %wExe%
chrome := UIA.ElementFromHandle(wExe)
URLEditElement := chrome.FindFirstWithOptions(, "Type=Edit", 2)
maybeZoom := UIA.CreateTreeWalker("Type=Button").GetNextSiblingElement(URLEditElement)
if maybeZoom && RegExMatch(maybeZoom.Name, " (\d+)%$", zoom) && (zoomPercent := zoom1)
    MsgBox, % "Current zoom percent is " zoomPercent "%"
Else
    MsgBox, % "Zoom button wasn't found, it's probably 100%"
ExitApp

Post Reply

Return to “Ask for Help (v1)”