Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[help with code] high cpu usage #109

Closed
skhrlx opened this issue Jan 29, 2022 · 2 comments
Closed

[help with code] high cpu usage #109

skhrlx opened this issue Jan 29, 2022 · 2 comments

Comments

@skhrlx
Copy link

skhrlx commented Jan 29, 2022

So, currently this is my code, i need to constantly check if the left mouse button is pressed, but, this code is taking about 25% of my CPU. How i can solve this problem?

import mouse

def main():

while True:
    if mouse.is_pressed(button='left'):
        print('Left mouse is down!')

if name == 'main':
main()

@re1von
Copy link

re1von commented Jan 30, 2022

You can use callback:

import mouse

if __name__ == '__main__':
    mouse.on_button(lambda: print('Left mouse is down!'), buttons=mouse.LEFT, types=mouse.DOWN)
    input('Press <Enter> to exit.\n')

@skhrlx
Copy link
Author

skhrlx commented Jan 30, 2022

Thanks bro! It solved my problem.

@skhrlx skhrlx closed this as completed Jan 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants