Python Forum

Full Version: Mouse lib keeps dropping same error
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi. I have lost all my hopes fixing this issiue. Can anyone help?

import mouse
from tkinter import *
import time
import os

run = type(True)

def noclick():
    run = False
    exit()

def clicker():
    cap = float(e)
    while (run == True):
        mouse.click("left")
        time.sleep(cap)

mouse.on_double_click(lambda: exec(clicker()))
mouse.on_right_click(lambda: exec(noclick()))
print("Literaly a clicker for POPCAT")
print("Enter number (the less the faster it goes)")
print("Right click on mouse to turn the script off")
e = input("Time gaps between clicks: ")
print("Double click to activate")
Error:
mouse.on_double_click(lambda: exec(clicker())) TypeError: exec() arg 1 must be a string, bytes or code object
Looks like it wants a function, not for you to call the function. So should probably be something like:

mouse.on_double_click(clicker)
mouse.on_right_click(noclick)
(Apr-13-2021, 03:46 PM)bowlofred Wrote: [ -> ]Looks like it wants a function, not for you to call the function. So should probably be something like:

mouse.on_double_click(clicker)
mouse.on_right_click(noclick)

Looks like it worked! Smile But I got another problem. It does not do the noclick function anymore. Doh
What is the behavior when you try? It looks like it should stop the program via the exit(). Does that not happen?

Also, what is the purpose of this line?

run = type(True)
Setting a flag to True I could see, but what is the return value of type() for?
(Apr-14-2021, 12:06 AM)bowlofred Wrote: [ -> ]What is the behavior when you try? It looks like it should stop the program via the exit(). Does that not happen?

Also, what is the purpose of this line?

run = type(True)
Setting a flag to True I could see, but what is the return value of type() for?
It wont close the app. You can press it as long as you like. It even does not run the line. Doh Is it a problem with
mouse.on_right_click(noclick)
?
More likely a problem with while/sleep blocking noclick from running. Does the program exit if you right click before double clicking?
(Apr-14-2021, 12:08 PM)deanhystad Wrote: [ -> ]More likely a problem with while/sleep blocking noclick from running. Does the program exit if you right click before double clicking?
Yes
I've never used that module before. I can get information from it (mouse.hook() and mouse.get_position() both report fine), but I can't seem to trigger callbacks on mouse.click() and similar. Not sure if there's a problem with the code, if the documentation is incomplete, or if I'm just doing something wrong. But it does seem a little touchy.