Python Forum

Full Version: Execute full script
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi dear users, in this code my function detects mouse click and while loop is refreshing x and y positions of mouse. I need these values together but my program is not executing. When i put while loop up, only while loop works. When i put function up, only function works. How to run them together ?
Thank you

import win32gui
from pynput.mouse import Listener
import time

counter = 0
def on_click(x, y, button, pressed):
    if pressed:
        global counter
        counter+=1
        print(counter)
with Listener(on_click=on_click) as listener:
    listener.join()

while True:
    x, y = win32gui.GetCursorPos()
    print(x,y)
    time.sleep(2)