6

How does one hold shift and and click with the mouse using pyautogui?

    pyautogui.hotkey('shift', click(1611, 600))

have tried the line above. But it doesn't work

Mr. Blue
  • 200
  • 2
  • 2
  • 13
Gabriel Cesar
  • 327
  • 2
  • 4
  • 10

2 Answers2

12

The hotkey() function only works with keys. To shift-click, you need code like this:

import pyautogui
pyautogui.keyDown('shift')
pyautogui.click()
pyautogui.keyUp('shift')
Al Sweigart
  • 11,566
  • 10
  • 64
  • 92
  • 2
    I JUST REALISED THAT THE GUY WHO WROTE AUTOMATE THE BORING STUFF ANSWERED MY QUESTION!!!! – Mr. Blue May 09 '19 at 12:20
  • Something really weird happened to me. I copied the code. It worked like twice then it stopped working for some reason. Any idea why? – teller.py3 Jun 06 '19 at 08:13
  • try with ` `pyautogui.keyDown('shift')` `pyautogui.mouseDown()` `pyautogui.keyUp('shift')` `pyautogui.mouseUp()` – okie Oct 25 '19 at 05:45
1

I tried the solution above but for some reason keyDown('shift') didnt work. I used the solution in this thread: keyDown function not working with shift key

pyautogui.keyDown('shiftleft')
pyautogui.keyDown('shiftright')
pyautogui.hotkey('right','right','ctrl','up')
pyautogui.keyUp('shiftleft')
pyautogui.keyUp('shiftright')