Package: adafruit-circuitpython-hid
IntroductionThis driver simulates USB HID devices. Currently keyboard and mouse are implemented.DependenciesThis driver depends on:Adafruit CircuitPythonPlease ensure all dependencies are available on the CircuitPython filesystem.
This is easily achieved by downloadingthe Adafruit library and driver bundle.Additional LayoutsThis library has an en-US layout. Please check out and expandthe library from Neradocfor additional layouts.Usage ExampleTheKeyboardclass sends keypress reports for a USB keyboard device to the host.TheKeycodeclass defines USB HID keycodes to send usingKeyboard.importusb_hidfromadafruit_hid.keyboardimportKeyboardfromadafruit_hid.keycodeimportKeycode# Set up a keyboard device.kbd=Keyboard(usb_hid.devices)# 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()TheKeyboardLayoutUSsends ASCII characters using keypresses. It assumes
the host is set to accept keypresses from a US keyboard.If the host is expecting a non-US keyboard, the character to key mapping provided byKeyboardLayoutUSwill not always be correct.
Different keypresses will be needed in some cases. For instance, to type an'A'on
a French keyboard (AZERTY instead of QWERTY),Keycode.Qshould be pressed.Currently this package provides onlyKeyboardLayoutUS. MoreKeyboardLayoutclasses could be added to handle non-US keyboards and the different input methods provided
by various operating systems.importusb_hidfromadafruit_hid.keyboardimportKeyboardfromadafruit_hid.keyboard_layout_usimportKeyboardLayoutUSkbd=Keyboard(usb_hid.devices)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('$')TheMouseclass simulates a three-button mouse with a scroll wheel.importusb_hidfromadafruit_hid.mouseimportMousem=Mouse(usb_hid.devices)# 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)TheConsumerControlclass emulates consumer control devices such as
remote controls, or the multimedia keys on certain keyboards.importusb_hidfromadafruit_hid.consumer_controlimportConsumerControlfromadafruit_hid.consumer_control_codeimportConsumerControlCodecc=ConsumerControl(usb_hid.devices)# Raise volume.cc.send(ConsumerControlCode.VOLUME_INCREMENT)# Pause or resume playback.cc.send(ConsumerControlCode.PLAY_PAUSE)DocumentationAPI documentation for this library can be found onRead the Docs.For information on building library documentation, please check outthis guide.ContributingContributions are welcome! Please read ourCode of Conductbefore contributing to help this project stay welcoming.