from time import sleep
import pyautogui
import keyboard
ENTER = "enter"
ESCAPE = "escape"
def writing_data_file():
if keyboard.is_pressed(ENTER):
sleep(0.5)
cursor_position = pyautogui.position()
print(cursor_position)
with open("cursor_position.txt", "a") as file:
file.write("{0}\n".format(cursor_position))
if keyboard.is_pressed(ESCAPE):
quit()
while True:
writing_data_file()