31 lines
1.1 KiB
Python
31 lines
1.1 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""Mock 后端:记录动作,无真实输入。开发/测试用。"""
|
|
import time
|
|
|
|
|
|
class MockBackend:
|
|
|
|
def __init__(self, log=None):
|
|
self.log = log if log is not None else []
|
|
self._screen = (1920, 1080)
|
|
|
|
def click(self, x, y, button='left', clicks=1):
|
|
self.log.append({'act': 'click', 'x': int(x), 'y': int(y),
|
|
'button': button, 'clicks': int(clicks)})
|
|
time.sleep(0.02)
|
|
return {'ok': True, 'clicked': [int(x), int(y)], 'backend': 'mock'}
|
|
|
|
def move(self, x, y):
|
|
self.log.append({'act': 'move', 'x': int(x), 'y': int(y)})
|
|
time.sleep(0.01)
|
|
return {'ok': True, 'backend': 'mock'}
|
|
|
|
def keypress(self, key):
|
|
self.log.append({'act': 'keypress', 'key': str(key)})
|
|
time.sleep(0.01)
|
|
return {'ok': True, 'key': str(key), 'backend': 'mock'}
|
|
|
|
def type_text(self, text):
|
|
self.log.append({'act': 'type_text', 'text': str(text)})
|
|
time.sleep(0.01 * len(text))
|
|
return {'ok': True, 'typed': str(text), 'backend': 'mock'} |