aboutsummaryrefslogtreecommitdiff
path: root/readme.rst
blob: f28553803b5a2ba4cb0634df81eb1296118abfbc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
.. role:: json(code)
   :language: json

=======================
Smart Macropad with KMK
=======================

.. contents::
   :depth: 2

-------------
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
============

.. code:: bash

    python3 -m pip install pystray pyserial zope.component

for debian you may need to install :

.. code:: bash

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

Configuration
=============

The configuration lies in an ini file:

Serial connection
-----------------

.. code:: ini

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


Initialize a connection directly with the macropad

Socket connection
-----------------

.. code:: ini

    [connexion.socket]
    port = 9999
    host = localhost

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

Socket server
-------------

.. code:: ini

    [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
-----------

.. code:: ini

    [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):

.. code:: json

    {"layer_name": "keymap"}

the keymap can be:

:a string:

    The key name will be sent: :json:`"A"`

:a list:

    All the keys will be chained in a single stroke: :json:`["^", "A"]`

:a dictionnary:

    Used to create custom sequences: :json:`{"seq": ["/", "W", "C", "ENTER"]}`

:null:

    The key will do nothing.

.. code:: json

    { "Example": [
        {"seq": ["A", "B", "C"]}, ["^", "R"], ["^", "T"], ["^", "W"],
        null, null, null, null
    ]}

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

.. _`to read or store json`: https://docs.circuitpython.org/en/latest/docs/library/json.html

.. Reading message
.. ---------------
..
.. The endpoint can also send a message to the application. For now, the message
.. is a raw string with the name of the layer.
..
.. When the application receive such message, it will look for the active window
.. in the desktop, and register the application with this layer. If this
.. application is selected again, the application will ask the endpoint to switch
.. to the same layer again.

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 device
----------