Giter Club home page Giter Club logo

zero-hid's Introduction

HID python library for emulating mouse and keyboard on PI.

Setup

  1. Install apt dependencies
sudo apt-get update
sudo apt-get install -y git python3-pip
  1. install usb gadget module
  2. Install zero-hid with pip
pip3 install zero-hid

Usage

Note: You should connect the data usb port (left one) to the raspberry, and NOT the power port

  • Control mouse
from zero_hid import Mouse
m = Mouse()
for i in range(5):
    m.move(10, 10)
  • Control keyboard
from zero_hid import Keyboard

k = Keyboard()
k.type('Hello world!')

Features

  • Relative / Absolute mouse movements
  • Left / Right / Middle click
  • Scrolling
  • Typing
  • Hot keys
  • Drag and Drop
  • Easy to setup
  • Comprehensive Testing

Examples

see examples

Tests

Raspberry Pi Model Raspbian Version Kernel Version
Raspberry Pi 4 Raspbian 12 6.1
Raspberry Pi Zero Raspbian 5.10 -

Gotaches

Error when installing with pip

error: externally-managed-environment

See how-solve-error-externally-managed-environment-when-installing-pip3

Or simply execute

sudo rm -rf /usr/lib/python3.11/EXTERNALLY-MANAGED

zero-hid's People

Contributors

thewh1teagle avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

zero-hid's Issues

Reading status of CapsLock, NumLock, ScrollLock Leds

If you plug 2x keyboards in a system you will see both will sync the lock leds. Most operating systems sync the LED on all keyboards. In the Arduino HID library, there is a UsbEventCallback that will send any connected keyboards a change in LED state.. Is there any way to read the current system status of the LEDs? Code in the Arduino HID library does not sync the LEDs, but it can easily be done once the LED statuses are captured.

Here is an example of Arduino HID code for the event handler when the LEDs change state. Is there any possibility to implement the same in this Python library?

static void usbEventCallback(void* arg, esp_event_base_t event_base, int32_t event_id, void* event_data){
	if(event_base == ARDUINO_USB_HID_KEYBOARD_EVENTS){
	    arduino_usb_hid_keyboard_event_data_t * data = (arduino_usb_hid_keyboard_event_data_t*)event_data;
	    	Serial.printf("HID KEYBOARD LED: NumLock:%u, CapsLock:%u, ScrollLock:%u\n", data->numlock, data->capslock, data->scrolllock);
	    }
	}
}

Problem of HID interface

HID does not seem to work on Raspbian GNU/Linux 11 (bullseye).

I am running the keyboard example from the readme.

Process ProcessWithResult-1:
Traceback (most recent call last):
  File "/usr/lib/python3.9/multiprocessing/process.py", line 315, in _bootstrap
    self.run()
  File "/home/aliner/.local/lib/python3.9/site-packages/zero_hid/hid/write.py", line 45, in run
    result.return_value = self._target(*self._args, **self._kwargs)
  File "/home/aliner/.local/lib/python3.9/site-packages/zero_hid/hid/write.py", line 65, in _write_to_hid_interface_immediately
    hid_handle.write(bytearray(buffer))
BrokenPipeError: [Errno 108] Cannot send after transport endpoint shutdown
Traceback (most recent call last):
  File "/home/aliner/zero-hid-test/keyboard.py", line 4, in <module>
    k.type('Hello world!')
  File "/home/aliner/.local/lib/python3.9/site-packages/zero_hid/Keyboard.py", line 30, in type
    send_keystroke(self.dev, mods, keys[0])
  File "/home/aliner/.local/lib/python3.9/site-packages/zero_hid/hid/keyboard.py", line 8, in send_keystroke
    hid_write.write_to_hid_interface(keyboard_path, buf)
  File "/home/aliner/.local/lib/python3.9/site-packages/zero_hid/hid/write.py", line 93, in write_to_hid_interface
    raise WriteError(
zero_hid.hid.write.WriteError: Failed to write to HID interface: /dev/hidg0. Is USB cable connected and Gadget module installed? check https://git.io/J1T7Q

Capslock status of host

When sending characters thru keyboard emulation, and the host computer has a secondary keyboard installed with capslock ON. The characters sent from the Raspberry PI have the case invented. Example sending 'Hello' will result in 'hELLO'. Is there any feature to counter measure this?

Sending absolute positions for mouse movement

In the current implementation, only relative mouse positioning is exposed to Python.

Is it possible to send absolute positions?

If there is a buffer structure reference that you are aware of I can implement the bindings and send a PR.

License?

Hi,

Is this licensed as MIT or GPL?
In setup.py it's listed as MIT, but LICENSE.txt says GPL. I would prefer MIT, fwiw.

Thanks for a great library!

Enable Azerty

Hey there,

I don't understand how can i enable the AZERTY output, for kerboard type method.

Thank's in advance

copy keymaps folder to package when building

config package build setup to include keymaps folder

https://github.com/thewh1teagle/zero-hid/blob/main/MANIFEST.IN

$ python3
Python 3.9.7 (default, Aug 31 2021, 13:28:12)
[GCC 11.1.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import zero_hid
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/user/.local/lib/python3.9/site-packages/zero_hid/__init__.py", line 2, in <module>
    from .Keyboard import Keyboard
  File "/home/user/.local/lib/python3.9/site-packages/zero_hid/Keyboard.py", line 11, in <module>
    class Keyboard:
  File "/home/user/.local/lib/python3.9/site-packages/zero_hid/Keyboard.py", line 12, in Keyboard
    US_KEYBOARD = json.loads( pkgutil.get_data(__name__, "keymaps/US.json").decode() )
  File "/usr/lib/python3.9/pkgutil.py", line 639, in get_data
    return loader.get_data(resource_name)
  File "<frozen importlib._bootstrap_external>", line 1039, in get_data
FileNotFoundError: [Errno 2] No such file or directory: '/home/user/.local/lib/python3.9/site-packages/zero_hid/keymaps/US.json'

What measure does the x and y move in is it pixels?

What measure does the x and y move in is it pixels or is it something different. Also is there a way to bypass the 127 limit for the x,y movement in one movement without using a loop or calling the move method twice?

Typo in Homepage on PyPI

Hi, thanks a lot for this lib, helped a lot in my recent tinkering with Pi Zero.

I came across this lib onb PyPI, but when I wanted to go to Homepage I got 404 GitHub page. Nevertheless I managed to find this repo.

It seems that there is a typo in the package configuration, so instead of pointing to https://pypi.org/project/zero-hid/ it points to https://pypi.org/project/zero_hid/ with underscore instead of hyphen.

This is not strictly a issue with the lib, but I wasn't able to come up with any other way to report that, mainly because you set the email to a mock one.

Take care and happy new year ๐ŸŽ†

[Errno 108] Cannot send after transport endpoint shutdown

Thank you for the repo.

I test it with Linux raspberrypi 5.15.32-v7+
I was testing it and I was getting the current issue: [Errno 108] Cannot send after transport endpoint shutdown. This was because I was using a USB HUB HAT, after remove it, worked perfectly

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.