I'm working on a well-known SysTrayIcon example, and need to handle both single click and double click.
def notify(self, hwnd, msg, wparam, lparam):
if lparam==win32con.WM_LBUTTONDBLCLK:
self.execute_menu_option(self.default_menu_index + self.FIRST_ID)
elif lparam==win32con.WM_RBUTTONUP:
self.show_menu()
elif lparam==win32con.WM_LBUTTONUP:
pass
return True
I know that this involves creating a timer:
But what is the best way to accomplish it in "pure" python (that is ctypes/pywin32 only, without qt, wx or gtk) ? Create a thread by myself? Or start a some kind of a windows timer that would generate WM_TIMER message for me when necessary?
PS I've found a proper way to ask windows about the user's preference concerning double click time here.
PPS I've also read an opinion of how bad it is to handle both single and double click here.
You can use pywin32
's timer
module. Set a double-click flag and start the timer in the click callback, and clear the double-click flag in the timer callback, and kill the timer in the click callback after detecting a double-click.
To start a timer:
timer_id = set_timer(delay_period, callback)
To stop the timer:
kill_timer(timer_id)