asweigart / pyautogui

A cross-platform GUI automation Python module for human beings. Used to programmatically control the mouse & keyboard.
BSD 3-Clause "New" or "Revised" License
10.22k stars 1.24k forks source link

Feature request - what about Ctrl-scroll-up/scroll-down #653

Open Jancs-E opened 2 years ago

Jancs-E commented 2 years ago

Hi! Some times web-pages open in zoomed-in (max-ed) view and it is required to zoom it out in order to get to the general view. Is it possible to have such function in pyautogui?

P.S. Merry Christmas!

Jancs-E commented 2 years ago

excuse me - may be it is sort of such solution: pyautogui.keyDown('ctrl') # hold down the key pyautogui.scroll(10) # scroll up 10 "clicks" pyautogui.keyUp('ctrl') # release the key ... do smth ... pyautogui.keyDown('ctrl') # hold down the key pyautogui.scroll(-10) # scroll down 10 "clicks" pyautogui.keyUp('ctrl') # release the key

becauseimnoob commented 1 year ago

excuse me - may be it is sort of such solution: pyautogui.keyDown('ctrl') # hold down the key pyautogui.scroll(10) # scroll up 10 "clicks" pyautogui.keyUp('ctrl') # release the key ... do smth ... pyautogui.keyDown('ctrl') # hold down the key pyautogui.scroll(-10) # scroll down 10 "clicks" pyautogui.keyUp('ctrl') # release the key

this doesn't work

JayRizzo commented 1 year ago

If you want to do this you must, Run your code & it move your mouse to and "Click" in the browser to active it or do an ALT + TAB. Then you can use the pyautogui system keys

Example to do yourself. RESET Zoom (NUMBER PAD or 10/key Zero only the number zero select the 10th tab)

Windows: Ctrl + 0 Mac: Command + 0(zero).

this is what you are looking for.

Make sure your browser you can alt tab from your terminal/command window then run the following:


import pyautogui
pyautogui.hotkey('command', 'tab')                                # switch over to the browser
pgui.click(x=1216, y=437, clicks=1, interval=0.25, button="left") # click into the browser window.
pyautogui.hotkey('esc')                                           # incase someone was in a "Find/Search menu."  
pyautogui.hotkey('command', 'num0')                               # reset browser for windows zoom level to zero
pyautogui.hotkey('command', '+')                                  # set browser zoom level increase by 1
pyautogui.hotkey('command', '-')                                  # set browser zoom level decrease by 1
pyautogui.hotkey('command', '+')                                  # set browser zoom level increase by 1
pyautogui.hotkey('command', '+')                                  # set browser zoom level increase by 1
pyautogui.hotkey('command', '+')                                  # set browser zoom level increase by 1
pyautogui.hotkey('command', '+')                                  # set browser zoom level increase by 1
pyautogui.hotkey('command', 'fn', '0')                            # reset browser for MAC OS zoom level to zero

The 10key keys are not mapped yet for Mac OSx I used function to get to the desired behaviour. https://github.com/asweigart/pyautogui/blob/master/pyautogui/_pyautogui_osx.py#L174

they are mapped for windows. https://github.com/asweigart/pyautogui/blob/master/pyautogui/_pyautogui_win.py#L169

and x11 https://github.com/asweigart/pyautogui/blob/master/pyautogui/_pyautogui_x11.py#L209