Python Forum
Is there a way to read the time between clicks?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Is there a way to read the time between clicks?
#1
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
Reply
#2
you can use timeit: https://docs.python.org/3/library/timeit.html
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Formatting a date time string read from a csv file DosAtPython 5 1,162 Jun-19-2023, 02:12 PM
Last Post: DosAtPython
  Is it possible to make a program recognize how many clicks it has had on the monitor? jao 0 1,129 Feb-25-2022, 06:31 PM
Last Post: jao
  Setup Portable Python on Windows for script starts with double clicks? pstein 0 1,778 Feb-18-2022, 01:29 PM
Last Post: pstein
  How to read rainfall time series and insert missing data points MadsM 4 2,125 Jan-06-2022, 10:39 AM
Last Post: amdi40
  how to change the range of read CSV file every time python file runs greenpine 6 4,382 Dec-08-2020, 10:11 PM
Last Post: greenpine
  How to read CSV file one row at the time in a range and some delay in between greenpine 2 4,673 Nov-20-2020, 02:26 PM
Last Post: greenpine
  Read CSV error: python KeyError: 'Time' charlicruz 1 5,106 Jun-27-2020, 09:56 AM
Last Post: charlicruz
  Read 2 temperatures in Real Time from Arduino linkxxx 0 1,894 Aug-29-2019, 11:27 AM
Last Post: linkxxx
  Detect finger clicks/snaps using Python fwinter102 0 2,005 Aug-12-2019, 04:02 PM
Last Post: fwinter102
  Is there any way to simulate clicks/typing to an inactive window using Python? Nwb 1 5,852 Jun-11-2018, 08:56 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020