有没有办法使用 python 来检测 "screens" 上的移动?

Is there a way to detect movement on "screens" using python?

例如,如果我在玩某个游戏,我想检查我是否在移动。那么,为此,有没有办法使用 python 来检测玩家的动作?如果可能,请提出一些想法。 提前致谢。

您可以使用 pynput

from pynput.mouse import Controller

mouse = Controller()

before = mouse.position

while True:
    current = mouse.position
    if before != current:
        print('Movement detected')
    before = current

变量before引用当前循环之前的移动,我主要检查当前位置是否与之前的迭代不同

您还可以检查键盘按键

pypi docs

回复你的评论,也是可以的,这次使用pyautogui

import pyautogui

before = pyautogui.screenshot()

while True:
    current = pyautogui.screenshot()
    if before != current:
        print('Screen is different')
    before = current

pypi docs