Protocol (v2, being implemented)
- extra bit for checksum + start code
- start code should maybe allow for settings? like for [idk I used to have an idea for this one]
- might need to slow down the rate just a bit
- do the math to have a built-in rate limiter in both PYTHON and arduinio code!
- or at least functionally. I donât know if youâll need the arduino side? I think python rate limit is all youâll need.
Â
Protocol (v1, being depreciated):
Example packet:
b'\x01\x82\x02\x8b\x00\x7f\x00'
Bits in packet:
0: keyboard key state
1: keyboard key being pressed
2: x coord
3: x coord
4: y coord
5: y coord
6: mouse press/release
Bit # | Purpose |
0 | keyboard key state |
1 | keyboard key being pressed |
2 | x coord |
3 | x coord |
4 | y coord |
5 | y coord |
6 | mouse press/release |
ã
€ | ã
€ |
Use | Method |
Keyboard key state | 1 = press, 0 = release (I think) |
Key being pressed | Denoted by numerical value: http://www.foreui.com/articles/Key_Code_Table.htm |
Coordinates | The two 8-bit integers are converted to binary, then shifted by 8 bits to the left. Theyâre then combined using a logical OR operation. This results in a 16-bit number, where the first 8 bits come from the first number and the second 8 bits come from the second number. This is denoted by the âhâ within "!BBhhB" |
Mouse press/release | Each mouse button has its own ID (1,2,3,etc). The ID for a press is just the given (or otherwise transformed0 button ID, and the âreleaseâ ID is given ID+ mouseLevelShift . This allows us to just add 4 (for example) to Button_ID_1 , and now 1 is press, 5 is release |
Example implementation:
packet = pack("!BBhhB", key_state, key , x, y, mouse)
if serialComms: ser.write(packet)
Implementation as a function:
import serial.tools.list_ports import serial from struct import pack from debug_settings import * #debug toggles selected_port = "COM5" #show_port_menu() print("Starting serial communication with:", selected_port) if serialComms: ser = serial.Serial(selected_port, 19200) #^or any other code to begin serial communication def serial_send(key_state, key, x, y, mouse_state): packet = pack("!BBhhB", key_state, key, x, y, mouse_state) if serialComms and printSerial: ser.write(packet) print(packet)
Calling the function:
serial_send(key_state, key, mouse_position.x, mouse_position.y, mouse_button_state)
Â
Example of proper keyboard output:
press:
release:
b'\x01a\x04\xe5\x00\x00\x00'
release:
b'\x00a\x04\xe5\x00\x00\x00'
â not case-sensitive
Â