用于模拟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枚举方向问题无法使用EAST   Java:将字符串转换为特定语言环境   javaspringboot&Thymeleaf为后续调用保存搜索表单的最佳方法   mapreduce程序中未调用java reducer   java如何将url中的Gif文件保存到手机中?   如何在JavaSwing中使用[Esc]键最小化JInternalFrame?   java创建了一个包含100个按钮、80个空按钮和20个随机按钮的网格布局   如何在java中使用数组对2d字符串数组中的每一行进行排序。分类   java无法识别的SSL消息,纯文本连接?例外   为什么Java编译器允许在抛出部分列出方法无法抛出的异常   java将预测数组添加到训练数组   java从Ajax调用获取响应文本   使用改型2的java应用程序等待一分钟后退出