From 5612b78207de3f6d477d7d199c3767200851191d Mon Sep 17 00:00:00 2001 From: TDHster <43290128+TDHster@users.noreply.github.com> Date: Thu, 15 Feb 2024 17:32:02 +0400 Subject: [PATCH] Update mouse-usage.rst Main problem was that event may not have attribute .button as the error indicates. mouse.Events() can have 3 main types: pynput.mouse.Events.Click, pynput.mouse.Events.Move and pynput.mouse.Events.Scroll (as far as I know) And among those three, last two of those do not have attribute .button surely. So if we want to handle this problem, I guess we need to use exception handling. https://stackoverflow.com/questions/73543563/attributeerror-move-object-has-no-attribute-button-mouse-listener-with-pyn --- docs/mouse-usage.rst | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/docs/mouse-usage.rst b/docs/mouse-usage.rst index 0349ad4c..57be26e8 100644 --- a/docs/mouse-usage.rst +++ b/docs/mouse-usage.rst @@ -156,12 +156,14 @@ To iterate over mouse events, use the following code:: from pynput import mouse - # The event listener will be running in this block with mouse.Events() as events: for event in events: - if event.button == mouse.Button.right: - break - else: + try: + if event.button == mouse.Button.right: + print('Right button clicked!') + break + except: pass + finally: print('Received event {}'.format(event)) Please note that the iterator method does not support non-blocking operation,