gpt-3.5-turbo-0613· openai
Suzhen/CodeChat
In python, write a function to print coordinates on the screen where mouse clicks.
- User
In python, write a function to print coordinates on the screen where mouse clicks.
- Assistant
You can use the
pyautoguilibrary in Python to achieve this. Thepyautoguilibrary provides functions to control the mouse and keyboard, including getting the current position of the mouse pointer. Here's an example function that will print the coordinates on the screen when the user clicks the mouse:import pyautogui def print_mouse_coordinates(): while True: try: x, y = pyautogui.position() print(f"Mouse clicked at coordinates: ({x}, {y})") # To stop the program, you can use Ctrl + C or close the terminal except KeyboardInterrupt: break print_mouse_coordinates()When you run this function, it will continuously print the coordinates of the mouse pointer whenever a click occurs. To stop the program, you can press Ctrl + C in the terminal or close the terminal window.