Python Forum

Full Version: Is there a way to read the time between clicks?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Fellows, I need some help here. Im trying to do a code that read the time between lefts clicks while right buttom is pressed. If the clicking is slow it will do thing1. If meduim velocity thing 2 and if the clicking is fast will do thing 3.

Would be great if the time count was 100% accurate

What I have done so far:

import win32api
import time

def lmb_down():  # Returns true if the left mouse button is pressed
    lmb_state = win32api.GetKeyState(0x01)    
    return lmb_state < 0
 
def rmb_down():  # Returns true if the right mouse button is pressed
    rmb_state = win32api.GetKeyState(0x02)
    return rmb_state < 0

def main_function():
    start = time.time()
    while rmb_down():
        while lmb_down():
            end = time.time()
            elapsed = end - start
            if elapsed > 0.4:
                print(elapsed, 'slow click')
            elif elapsed >= 0.00000000001 <= 0.4:
                print(elapsed, 'medium click')
            elif elapsed < 0.00000000001:
                print(elapsed, 'fast clicking')
 
while True:    
    main_function()
appreciate any help