用于模拟hid设备的circuitpython帮助程序库。

adafruit-circuitpython-hid的Python项目详细描述


简介

Documentation StatusDiscordBuild Status

此驱动程序模拟USB HID设备。目前已经实现了键盘和鼠标。

依赖关系

此驱动程序取决于:

请确保circuitpython文件系统上的所有依赖项都可用。 这很容易通过下载来实现 the Adafruit library and driver bundle

用法示例

Keyboard类向主机发送USB键盘设备的按键报告。

Keycode类定义要使用Keyboard发送的USB HID密钥代码。

fromadafruit_hid.keyboardimportKeyboardfromadafruit_hid.keycodeimportKeycode# Set up a keyboard device.kbd=Keyboard()# Type lowercase 'a'. Presses the 'a' key and releases it.kbd.send(Keycode.A)# Type capital 'A'.kbd.send(Keycode.SHIFT,Keycode.A)# Type control-x.kbd.send(Keycode.CONTROL,Keycode.X)# You can also control press and release actions separately.kbd.press(Keycode.CONTROL,Keycode.X)kbd.release_all()# Press and hold the shifted '1' key to get '!' (exclamation mark).kbd.press(Keycode.SHIFT,Keycode.ONE)# Release the ONE key and send another report.kbd.release(Keycode.ONE)# Press shifted '2' to get '@'.kbd.press(Keycode.TWO)# Release all keys.kbd.release_all()

KeyboardLayoutUS使用按键发送ascii字符。它假设 主机设置为接受来自美国键盘的按键。

如果主机需要非美国键盘,则 KeyboardLayoutUS并不总是正确的。 在某些情况下需要不同的按键。例如,键入'A'on 法语键盘(AZERTY而不是QWERTY),Keycode.Q应该按下

目前这个包只提供KeyboardLayoutUS。更多KeyboardLayout 可以添加类来处理非美国键盘和提供的不同输入方法 通过各种操作系统。

fromadafruit_hid.keyboardimportKeyboardfromadafruit_hid.keyboard_layout_usimportKeyboardLayoutUSkbd=Keyboard()layout=KeyboardLayoutUS(kbd)# Type 'abc' followed by Enter (a newline).layout.write('abc\n')# Get the keycodes needed to type a '$'.# The method will return (Keycode.SHIFT, Keycode.FOUR).keycodes=layout.keycodes('$')

Mouse类模拟带有滚轮的三按钮鼠标。

fromadafruit_hid.mouseimportMousem=Mouse()# Click the left mouse button.m.click(Mouse.LEFT_BUTTON)# Move the mouse diagonally to the upper left.m.move(-100,-100,0)# Roll the mouse wheel away from the user one unit.# Amount scrolled depends on the host.m.move(0,0,-1)# Keyword arguments may also be used. Omitted arguments default to 0.m.move(x=-100,y=-100)m.move(wheel=-1)# Move the mouse while holding down the left button. (click-drag).m.press(Mouse.LEFT_BUTTON)m.move(x=50,y=20)m.release_all()# or m.release(Mouse.LEFT_BUTTON)

ConsumerControl类模拟使用者控制设备,如 遥控器,或某些键盘上的多媒体键

circuitpython 3.0中的new。

fromadafruit_hid.consumer_controlimportConsumerControlfromadafruit_hid.consumer_control_codeimportConsumerControlCodecc=ConsumerControl()# Raise volume.cc.send(ConsumerControlCode.VOLUME_INCREMENT)# Pause or resume playback.cc.send(ConsumerControlCode.PLAY_PAUSE)

Gamepad类模拟一个有16个按钮的双操纵杆游戏板。

circuitpython 3.0中的new。

fromadafruit_hid.gamepadimportGamepadgp=Gamepad()# Click gamepad buttons.gp.click_buttons(1,7)# Move joysticks.gp.move_joysticks(x=2,y=0,z=-20)

贡献

欢迎投稿!请阅读我们的Code of Conduct 在帮助这个项目保持热情之前。

本地建筑

要在本地构建此库,您需要安装 circuitpython-build-tools包装。

python3 -m venv .env
source .env/bin/activate
pip install circuitpython-build-tools

安装后,请确保您处于虚拟环境中:

source .env/bin/activate

然后运行生成:

circuitpython-build-bundles --filename_prefix adafruit-circuitpython-hid --library_location .

斯芬克斯文件

sphinx用于根据代码中的rst文件和注释构建文档。第一, 安装依赖项(请随意重用上面的虚拟环境):

python3 -m venv .env
source .env/bin/activate
pip install Sphinx sphinx-rtd-theme

现在,激活虚拟环境后:

cd docs
sphinx-build -E -W -b html . _build/html

这将把文档输出到docs/_build/html。在浏览器中打开index.html以 查看它们。它还将(由于-w)错误的任何警告,像特拉维斯将。这是个很好的方法 本地验证它将通过。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java Intellij通过方法中的包查找用法   java中VS代码和打包命名的问题   将java CMS功能集成到具有高度动态内容的网站(Lucene/Mysql/Nosql)的策略   oracle的java类强制转换异常。jdbc。驾驶员OracleConnection   字节码向JVM添加上指令   如何在抽象类中执行java方法?   java是否可以在apache访问日志中排除指定的GET参数?(作者:W7开发环境)   java如何获取已安装音频播放器的列表?   尝试向HS学生展示如何使用Java访问MS数据库   使用正则表达式java对给定行中的特定字符串进行计数   java JOOQ Select查询中的Select计数   方法Java,如何从二维双精度数组中找到特定值?   获取图像URL的java正则表达式   java在切换到新的窗口驱动程序后找不到元素