Как отслеживать нажатие на левую и правую кнопки мыши

Будьте добры, подсказать, как можно отследить нажатие по левой и правой кнопки мыши на python 3.8 ПРИМЕР:

if mouseleft  == pressed:
    press(rightmouse)

Ответы (1 шт):

Автор решения: Alteration
from ctypes import windll, Structure, c_ulong, byref, c_ushort
import time


class POINT(Structure):
    _fields_ = [("x", c_ulong), ("y", c_ulong)]

VK_LBUTTON = 0x01               # Left mouse button
VK_RBUTTON = 0x02               # Right mouse button

def queryMousePosition():
    pt = POINT()
    windll.user32.GetCursorPos(byref(pt))
    return { "x": pt.x, "y": pt.y}
###########################################

for t in range(60):
    pos = queryMousePosition()
    print(pos)
    windll.user32.GetKeyState.restype = c_ushort
    if windll.user32.GetKeyState(VK_LBUTTON):
        eee = 0
        print(eee)
    if windll.user32.GetKeyState(VK_RBUTTON):
        eee = 1
        print(eee)
    time.sleep(0.1)

Код взят с Как отследить события мыши в python3

→ Ссылка