如何通过 Python 访问数位板笔数据?

编程入门 行业动态 更新时间:2024-10-08 01:21:20
本文介绍了如何通过 Python 访问数位板笔数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我需要通过 Python 访问 Windows 平板电脑笔数据(例如表面).我主要需要位置、压力和倾斜值.

I need to access a windows tablet pen data (such as the surface) via Python. I mainly need the position, pressure, and tilt values.

我知道如何访问 Wacom 笔数据,但 Windows 笔不一样.

I know how to access the Wacom pen data but the windows pen is different.

有一个名为 Kivy 的 Python 库可以处理多点触控,但它会将我的笔识别为手指 (WM_TOUCH) 而不是笔 (WM_PEN).

There is a Python library named Kivy that can handle multi-touch but it recognizes my pen as a finger (WM_TOUCH) and not as a pen (WM_PEN).

这是我的 Kivy 代码(不报告压力和倾斜):

This is my Kivy code (that doesnt report pressure and tilt):

 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()

有一个很棒的 processing 库,名为 平板电脑 仅适用于具有简单 API 的 Wacom 平板电脑(例如,tablet.getPressure())

There is a wonderful processing library named Tablet that only works with the Wacom tablet with a simple API (e.g., tablet.getPressure())

我需要这样的东西.

推荐答案

如果您想查看设备:

import pyglet
pyglet.input.get_devices()

如果您想查看设备控件:

if you want to see the devices controls:

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 平板电脑,没有倾斜传感器,但如果你有它,修改代码会很容易:

And now to get the data. I have a xp-pen g640 tablet and don't have tilt sensor, but if yours have it it will be easy to modify the code:

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()

这篇关于如何通过 Python 访问数位板笔数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-05-01 11:17:47,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1408570.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数位   数据   Python

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!