[help with code] high cpu usage
skhrlx opened this issue · comments
skhrlx commented
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 commented
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 commented
Thanks bro! It solved my problem.