aboutsummaryrefslogtreecommitdiff

Smart Macropad with KMK

The companion

The companion is running in the PC connected with the macropad. The application will control the keyboard and changes the keys depending of the application used.

Requirements

python3 -m pip install pystray pyserial zope.component

for debian you may need to install :

sudo apt install python3-pil.imagetk python3-serial python3-zope.component python3-pystray

Configuration

The configuration lies in an ini file:

Serial connection

[connexion.serial]
port = \\.\COM12

Initialize a connection directly with the macropad

Socket connection

[connexion.socket]
port = 9999
host = localhost

Use a proxy to connect with the keyboard (as client)

Socket server

[socket.serve]
port = 9999
host = localhost
name = The name of the application to associate with

Use a proxy to connect with the keyboard (as server)

The mapping

[mapping]
Mozilla Firefox = firefox.json
Teams = teams.json
irssi = irssi.json

Mapping list

When a new window is selected, the application will look in the table for a match, and send the corresponding layer to the endpoint.

Note

When using XLib, the application will match the name with both the CLASS or the NAME of the selected window

If the application receive a notification for a new layer, it will also register it, and store it for the session. This allow to make the application "learn" about the layer you want to use.

Serial connection

Sending message

The application send a json string to the endpoint (network or serial connection):

{"layer_name": "keymap"}

the keymap can be:

a string:The key named will be sent: "A" (you have to follow the named declared in the device)
a list:All the keys will be chained in a single stroke: ["^", "A"]
a dictionnary:Used to create custom sequences: {"seq": ["/", "W", "C", "ENTER"]}
null:The key will do nothing.
{ "Example": [
    {"seq": ["A", "B", "C"]}, ["^", "R"], ["^", "T"], ["^", "W"],
    null, null, null, null
]}

Network connection

You can relay the events to another one instance using the network. I'm using this when I'm connected over VNC in order to use the keyboard as if it was plugged directly in the host.

The client

There is a command-line client, which allow to send a layer directly to the device.

The client can work in interractive mode (usefull for testing), or in a one-shot action, sending the json file given with the parameter --layer

The device

CircuitPython provide a native library in order to read or store json, and firmware build upon it (like KMK) are easer to use with.