Likes_to_Program123
Likes_to_Program123

Reputation: 47

python: how to listen for mouse clicks and keypress at the same time

I want to create a program that if the user pressed shift and button-1 (left click), a GUI will pop up. However, I can only listen for key presses and mouse clicks separately using pynput. Is there a way to listen for those two things at the same time?

Upvotes: 0

Views: 5166

Answers (1)

Dawid Rutkowski
Dawid Rutkowski

Reputation: 410

Here is the simple solution:

https://github.com/boppreh/mouse

https://github.com/boppreh/keyboard

import mouse
import keyboard
import time

while True:
    if mouse.is_pressed(button='left') and keyboard.is_pressed('shift'):
        print("Left mouse button and shift is pressed")
        time.sleep(0.5)

Upvotes: 1

Related Questions