mouse
mouse copied to clipboard
ValueError: list.remove(x): x not in list
import mouse
def onMouseClicked():
mouse.unhook(onMouseClicked)
mouse.double_click()
mouse.click()
mouse.on_click(onMouseClicked)
mouse.wait(button='right', target_types=('double', ))
caused the exception
Traceback (most recent call last):
File "C:\Users\i\AppData\Local\Programs\Python\Python35-32\lib\site-packages\mouse\_generic.py", line 22, in invoke_handlers
if handler(event):
File "C:\Users\i\AppData\Local\Programs\Python\Python35-32\lib\site-packages\mouse\__init__.py", line 164, in handler
callback(*args)
File "D:\BaiduYunDownload\编程\Python\WindowsMouseHook.py", line 7, in onMouseClicked
mouse.unhook(onMouseClicked)
File "C:\Users\i\AppData\Local\Programs\Python\Python35-32\lib\site-packages\mouse\__init__.py", line 221, in unhook
_listener.remove_handler(callback)
File "C:\Users\i\AppData\Local\Programs\Python\Python35-32\lib\site-packages\mouse\_generic.py", line 72, in remove_handler
self.handlers.remove(handler)
ValueError: list.remove(x): x not in list
The callbacks given to on_something listeners are not added as raw hooks, so you can't remove them with unhook. But they do return hooks, so you can try calling unhook with the value returned by them.
But you are right, there should be a clearer way to do this, and a better error in this case.