Y
Y
yanelox2021-03-19 20:37:40
Python
yanelox, 2021-03-19 20:37:40

How to detect side mouse clicks?

how to detect side mouse clicks? I'm making a console macro in python with keybindings, I need it to detect pressing the side buttons of the mouse. Here is the code:

import keyboard as kb
import mouse
from time import sleep

i = 0
k = 0

st_key = input('Клавиша старт L: ')  
s_key = input('Клавиша старт R: ')
stop_key = input('Клавиша стоп: ')

def func():
    global i
    while i < 5:
            i += 1
            sleep(0.02)
            mouse.double_click(button = 'left')
    b = True
    i = 0

def fun():
    global k
    while k < 5:            
            k += 1
            sleep(0.02)
            mouse.double_click(button = 'right')
    l = True
    
    k = 0

def n():
    global b, i
    while True:
        if kb.is_pressed(st_key):
            func()

        if kb.is_pressed(s_key):
            fun()

        try:
            if b == True:
                i == 0
                b = False
        except:
            pass 

        try:
            if l == True:
                k == 0
                l = False
        except:
            pass 

        if kb.is_pressed(stop_key):
            break
n()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
HemulGM, 2021-03-20
@HemulGM

The side mouse buttons are also macros on the mouse itself. They either emulate keystrokes on the keyboard, or a separate action (double/triple click, etc.).
To determine that the button on the device was simply pressed, you need to smoke the mouse driver and work with it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question