[英]How to record multiple x/y coords of current mouse position with a key press in Python3
使用pyautogui
我可以使用以下方法pyautogui
獲取鼠標位置的 x/y 坐標:
pyautogui.position()
我想創建一個循環,每次按“a”時都會記錄鼠標懸停位置的 x/y 坐標,然后在按“b”時停止記錄。
你可以試試這個: - 這是一個簡短的 Python 3 程序,它會不斷地打印出鼠標光標的位置:
#! python3
import pyautogui, sys
print('Press Ctrl-C to quit.')
try:
while True:
x, y = pyautogui.position()
positionStr = 'X: ' + str(x).rjust(4) + ' Y: ' + str(y).rjust(4)
print(positionStr, end='')
print('\b' * len(positionStr), end='', flush=True)
except KeyboardInterrupt:
print('\n')
moveTo() 函數會將鼠標光標移動到您傳遞給它的 X 和 Y 整數坐標處。 可以為坐標傳遞 None 值以表示“當前鼠標光標位置”。 例如:
>>> pyautogui.moveTo(100, 200) # moves mouse to X of 100, Y of 200.
>>> pyautogui.moveTo(None, 500) # moves mouse to X of 100, Y of 500.
>>> pyautogui.moveTo(600, None) # moves mouse to X of 600, Y of 500.
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.