-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4aa1208
commit ae8a60e
Showing
14 changed files
with
1,989 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
Metadata-Version: 2.1 | ||
Name: Py-Keyboard | ||
Version: 0.0.2 | ||
Summary: Python wrapper for hid device | ||
Home-page: https://github.com/Danny-Dasilva/Py_Keyboard | ||
Author: Danny Dasilva | ||
Author-email: dannydasilva.solutions@gmail.com | ||
License: UNKNOWN | ||
Description: ## Python HID USB emulator | ||
|
||
Python Wrapper for emulating a HID USB device for the raspi zero w | ||
|
||
setup from https://randomnerdtutorials.com/raspberry-pi-zero-usb-keyboard-hid/ | ||
|
||
|
||
|
||
## git repo | ||
|
||
`pip3 install git+https://github.com/Danny-Dasilva/Py_Keyboard.git` | ||
## on a brand new pi zero w | ||
|
||
|
||
`git clone https://github.com/Danny-Dasilva/Py_Keyboard.git` | ||
|
||
in Py_Keyboard folder | ||
|
||
`source install.sh` | ||
|
||
|
||
example.py | ||
|
||
|
||
```python | ||
|
||
|
||
|
||
from Py_Keyboard.HID import Keyboard | ||
|
||
kbd = Keyboard() | ||
|
||
kbd.press("CONTROL ALT T") | ||
|
||
kbd.write('ls\n') | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
``` | ||
|
||
|
||
|
||
## to do | ||
|
||
`keycodes = layout.keycodes('$')` | ||
|
||
Test pip package import | ||
|
||
|
||
Platform: UNKNOWN | ||
Classifier: Programming Language :: Python :: 3 | ||
Description-Content-Type: text/markdown |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
README.md | ||
setup.py | ||
Py_Keyboard/API.py | ||
Py_Keyboard/HID.py | ||
Py_Keyboard/HID_old.py | ||
Py_Keyboard/__init__.py | ||
Py_Keyboard/ada_hid.py | ||
Py_Keyboard/byte_decoder.py | ||
Py_Keyboard/keycode.py | ||
Py_Keyboard.egg-info/PKG-INFO | ||
Py_Keyboard.egg-info/SOURCES.txt | ||
Py_Keyboard.egg-info/dependency_links.txt | ||
Py_Keyboard.egg-info/top_level.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Py_Keyboard |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
|
||
from time import sleep | ||
|
||
class device(): | ||
def __init__(self, string): | ||
self.string = string | ||
def write_report(report): | ||
with open('/dev/hidg0', 'rb+') as fd: | ||
fd.write(report.encode()) | ||
def write(string): | ||
#!/usr/bin/env python3 | ||
NULL_CHAR = chr(0) | ||
|
||
def write_report(report): | ||
with open('/dev/hidg0', 'rb+') as fd: | ||
fd.write(report.encode()) | ||
|
||
for c in string: | ||
#space | ||
if c == " ": | ||
write_report(NULL_CHAR*2+chr(44)+NULL_CHAR*5) | ||
#lowercase | ||
if ord(c) > 96: | ||
s = ord(c) - 93 | ||
write_report(NULL_CHAR*2+chr(s)+NULL_CHAR*5) | ||
#uppercasse | ||
if 64 < ord(c) < 91: | ||
a = ord(c) - 61 | ||
write_report(chr(32)+NULL_CHAR+chr(a)+NULL_CHAR*5) | ||
#numbers | ||
if 48 < ord(c) < 58: | ||
a = ord(c) - 19 | ||
write_report(NULL_CHAR*2+chr(a)+NULL_CHAR*5) | ||
# 0 | ||
if ord(c) == 48: | ||
a = ord(c) - 9 | ||
write_report(NULL_CHAR*2+chr(a)+NULL_CHAR*5) | ||
|
||
if c == '!': | ||
write_report(chr(32)+NULL_CHAR+chr(30)+NULL_CHAR*5) | ||
|
||
if c == '@': | ||
write_report(chr(32)+NULL_CHAR+chr(31)+NULL_CHAR*5) | ||
|
||
if c == '#': | ||
write_report(chr(32)+NULL_CHAR+chr(32)+NULL_CHAR*5) | ||
|
||
if c == '$': | ||
write_report(chr(32)+NULL_CHAR+chr(33)+NULL_CHAR*5) | ||
|
||
if c == '%': | ||
write_report(chr(32)+NULL_CHAR+chr(34)+NULL_CHAR*5) | ||
|
||
if c == '^': | ||
write_report(chr(32)+NULL_CHAR+chr(35)+NULL_CHAR*5) | ||
|
||
if c == '&': | ||
write_report(chr(32)+NULL_CHAR+chr(36)+NULL_CHAR*5) | ||
|
||
if c == '*': | ||
write_report(chr(32)+NULL_CHAR+chr(37)+NULL_CHAR*5) | ||
|
||
if c == '(': | ||
write_report(chr(32)+NULL_CHAR+chr(38)+NULL_CHAR*5) | ||
if c == ')': | ||
write_report(chr(32)+NULL_CHAR+chr(39)+NULL_CHAR*5) | ||
if c == '=': | ||
write_report(NULL_CHAR*2+chr(46)+NULL_CHAR*5) | ||
# if c == '{': | ||
# write_report(chr(32)+NULL_CHAR+chr(47)+NULL_CHAR*5) | ||
if c == '[': | ||
write_report(NULL_CHAR*2+chr(47)+NULL_CHAR*5) | ||
# if c == '}': | ||
# write_report(chr(32)+NULL_CHAR+chr(48)+NULL_CHAR*5) | ||
if c == ']': | ||
write_report(NULL_CHAR*2+chr(48)+NULL_CHAR*5) | ||
# if c == "\": | ||
# write_report(chr(32)+NULL_CHAR+chr(47)+NULL_CHAR*5) | ||
# if c == '|': | ||
# write_report(NULL_CHAR*2+chr(49)+NULL_CHAR*5) | ||
if c == ':': | ||
write_report(chr(32)+NULL_CHAR+chr(51)+NULL_CHAR*5) | ||
if c == ';': | ||
write_report(NULL_CHAR*2+chr(51)+NULL_CHAR*5) | ||
|
||
# if c == "'": | ||
# write_report(NULL_CHAR*2+chr(52)+NULL_CHAR*5) | ||
|
||
if c == '"': | ||
write_report(chr(32)+NULL_CHAR+chr(52)+NULL_CHAR*5) | ||
|
||
|
||
|
||
write_report(NULL_CHAR*8) | ||
|
||
def press(string): | ||
#!there is a better wayto do this but im lazy | ||
NULL_CHAR = chr(0) | ||
def writer(input): | ||
with open('/dev/hidg0', 'rb+') as fd: | ||
fd.write(bytes(string)) | ||
for word in string.split(): | ||
if word == "ENTER": | ||
device.write_report(NULL_CHAR*2+chr(40)+NULL_CHAR*5) | ||
if word == "CTRL-ALT-T": | ||
with open('/dev/hidg0', 'rb+') as fd: | ||
fd.write(b'\x05\0\x17\0\0\0\0\0') | ||
if word == "CTRL-ALT-DELETE": | ||
with open('/dev/hidg0', 'rb+') as fd: | ||
fd.write(b'\x05\0\x4c\0\0\0\0\0') | ||
|
||
|
||
device.write_report(NULL_CHAR*8) | ||
|
||
|
||
|
||
|
||
|
||
# to do | ||
# 54 , < | ||
# 55 . > | ||
# 56 / ? | ||
|
||
|
||
|
||
|
||
|
Oops, something went wrong.