Python でグラフィック タブレットをシミュレートしようとしていますが、その結果、カーソルの絶対位置を設定できるようにする必要があります。python-evdevとpython-libevdevを試しましたが、絶対位置を設定できません。EV_ABS の ABS_X と ABS_Y に値を書き込んでも、カーソル位置には何の影響もありません。シミュレートされたボタンと相対的な配置が完全に機能することに言及する価値があります。
x11のGnomeでManjaro 4.19を使用しています。
助けていただければ幸いです。事前に感謝します。
絶対カーソル位置を設定できる必要がある単純なコードを次に示しますが、そうではありません。
from evdev import UInput, AbsInfo, ecodes as e
import pyautogui
import subprocess
import time
cap = {
e.EV_KEY : [e.BTN_TOUCH],
e.EV_ABS : [
(e.ABS_X, AbsInfo(0, 0, 4080, 0, 0, 5080)),
(e.ABS_Y, AbsInfo(0, 0, 4080, 0, 0, 5080)),
(e.ABS_PRESSURE, AbsInfo(0, 0, 2040, 0, 0, 0))
]
}
ui = UInput(cap, name='example-device', version=0x3)
for i in range(0,10):
# assign driver to the default display
time.sleep(0.5)
process = subprocess.Popen(["xinput", "list"], shell=True, stdout=subprocess.PIPE)
output = process.stdout.read().decode("utf-8")
print(output)
if "example-device" in output:
print(output)
subprocess.Popen([
"xinput",
"map-to-output",
f"pointer:example-device",
"eDP1"
])
break
else:
raise Exception("Can't map device to display.")
# print cursor position befor cahnge
print(pyautogui.position())
# move mouse cursor
ui.write(e.EV_ABS, e.ABS_X, 20)
ui.write(e.EV_ABS, e.ABS_Y, 20)
ui.syn()
# print cursor position after cahnge
print(pyautogui.position())