我需要通过Python访问Windows平板电脑笔数据(例如表面)。我主要需要位置、压力和倾斜值。
我知道如何访问 Wacom 笔数据,但 Windows 笔不同。
有一个名为的Python库Kivy https://kivy.org/#home它可以处理多点触控,但它将我的笔识别为手指(WM_TOUCH)而不是笔(WM_PEN)。
这是我的 Kivy 代码(不报告压力和倾斜):
from kivy.app import App
from kivy.uix.widget import Widget
class TouchInput(Widget):
def on_touch_down(self, touch):
print(touch)
def on_touch_move(self, touch):
print(touch)
def on_touch_up(self, touch):
print("RELEASED!",touch)
class SimpleKivy4(App):
def build(self):
return TouchInput()
有一个美妙的加工 https://processing.org/图书馆名为Tablet http://processing.andrescolubri.net/libraries/tablet/仅适用于具有简单 API 的 Wacom 数位板(例如,tablet.getPressure()
)
我需要这样的东西。
如果您想查看设备:
import pyglet
pyglet.input.get_devices()
如果您想查看设备控件:
tablets = pyglet.input.get_devices() #tablets is a list of input devices
tablets[0].get_controls() #get_controls gives a list of possible controls of the device
现在获取数据。我有一台 xp-pen g640 平板电脑,没有倾斜传感器,但如果您有倾斜传感器,则可以轻松修改代码:
if tablets:
print('Tablets:')
for i, tablet in enumerate(tablets):
print(' (%d) %s' % (i , tablet.name))
i = int(input('type the index of the tablet.'))
device = tablets[i]
controls = device.get_controls()
df = pd.DataFrame()
window = pyglet.window.Window(1020, 576)
# Here you will have to write a line like "control_tilt_x = controls[j]" where j is
# the controls list index of the tilt control.
control_presion = controls[7]
Button = controls[3]
control_x =controls[5]
control_y =controls[6]
control_punta = controls[4]
control_alcance = controls [0]
name = tablets[9].name
try:
canvas = device.open(window)
except pyglet.input.DeviceException:
print('Failed to open tablet %d on window' % index)
print('Opened %s' % name)
@control_presion.event
def on_change(presion):
global df
df_temp = pd.DataFrame({'x':[control_x.value/(2**15)],
'y':[control_y.value/(2**16)],
'p':[control_presion.value/8],
't':[time.time()]})
df = pd.concat([df,df_temp])
pyglet.app.run()
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)