0

I am trying to hold shift key and at the same time click with the mouse. I searched the internet and found a stackoverflow question about this. This is the post: Pyautogui - Need to hold shift and click

Also the code in this post was working for like three times!

Then suddenly it stopped working. It is really strange. I also tried it with pynput. Here is my post: Holding shift key + mouse click

It seems like holding shift and clicking the mouse are working seperately.

However, together it seems not to work

This is the code:

import pyautogui
import time

time.sleep(2)
pyautogui.keyDown('shift')
pyautogui.click()
pyautogui.keyUp('shift')

I am running on windows OS

teller.py3
  • 822
  • 8
  • 22
  • 1
    Possible duplicate of [How to simulate a mouse click while holding the SHIFT key in Windows?](https://stackoverflow.com/questions/56469486/how-to-simulate-a-mouse-click-while-holding-the-shift-key-in-windows) – buræquete Jun 16 '19 at 03:28

2 Answers2

1

It looks working fine? Maybe use more keydown('shift') will make it

okie
  • 847
  • 6
  • 18
0

I will suggest you not to use pyautogui.
Its easy and simple with other modules. Install keyboard(for controlling keyboard) and mouse(for controlling mouse)

Here is a sample code that does what you want:

import keyboard, mouse       #< Importing the required modules
keyboard.press("shift")      #< Presses and holds the key
mouse.click("left")          #< Makes Left click
keyboard.release("shift")    #< Releases the held key
Nouman
  • 6,947
  • 7
  • 32
  • 60