qmk_firmware/keyboards/ergodox/keymaps/algernon/tools/text-to-log.py
Gergely Nagy 3e128552d9 Update the ergodox/algernon keymap to v1.7
Overall changes
===============

* The number row has been completely rearranged on both the **Base** and
  the **ADORE** layers.
* The number/function key behavior was changed: function keys are now on
  the **Media**.
* The `:`/`;` and `-`/`_` keys were put back to their thumb position on
  the bottom row, on both the **Base** and **ADORE** layers.
* The bottom large keys on the inner side of each half now function as
  [tmux](http://tmux.github.io/) keys: the left to send the prefix, the
  right to send the `display-panes` key. The left also doubles as a GNU
  screen prefix key, and sends `C-a` when double tapped.
* A number of functions, such as the **AppSel** layer, now require the
  `hid-commands` tool to be running, with the output of `hid_listen`
  being piped to it.

ADORE
=====

* `Y` and `X` have been swapped again.

Media/Navigation layer
======================

* The function keys are now on this layer.
* Mouse keys have been removed.
* Media start/stop/prev/next have been removed.
* `Print screen` has been removed.
* There is only one screen lock key now.

Heatmap
=======

* Fixed a few issues in the finger-stats calculation.
* The tool now also timestamps and saves all input lines to a logfile,
  which it loads on start, allowing one to continue the collection after
  upgrading the tool.
* The heatmap tool will now colorize the stats by default.
* The periodic stats are now printed in a more compact format.

Tools
=====

* Added a new tool, `tools/layer-notify` that listens to layer change
  events on the HID console, and pops up a notification on layer
  changes.
* Another new tool, `tools/text-to-log.py` has been added that converts
  arbitrary text to a keylogger output, which can be fed to the heatmap
  generator.
* A number of features have been moved to the `tools/hid-commands`
  utility. These generally are OS dependent, and are easier to implement
  on the software side.

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
2016-09-18 11:48:47 +02:00

108 lines
3.5 KiB
Python
Executable File

#!/usr/bin/env python3
import os
import sys
charmap = {
'9': [[1, 0]],
'7': [[2, 0]], '@': [[2, 5], [2, 0]],
'5': [[3, 0]], '*': [[2, 5], [3, 0]],
'3': [[4, 0]], '^': [[2, 5], [4, 0]],
'1': [[5, 0]], '$': [[2, 5], [5, 0]],
'0': [[8, 0]], '%': [[2, 5], [8, 0]],
'2': [[9, 0]], '!': [[2, 5], [9, 0]],
'4': [[10, 0]], '#': [[2, 5], [10, 0]],
'6': [[11, 0]], '&': [[2, 5], [11, 0]],
'8': [[12, 0]],
'`': [[0, 1]], '~': [[2, 5], [0, 1]],
'y': [[1, 1]], 'Y': [[2, 5], [1, 1]],
'w': [[2, 1]], 'W': [[2, 5], [2, 1]],
'g': [[3, 1]], 'G': [[2, 5], [3, 1]],
'l': [[4, 1]], 'L': [[2, 5], [4, 1]],
'm': [[5, 1]], 'M': [[2, 5], [5, 1]],
'[': [[6, 1]], '{': [[2, 5], [6, 1]], '(': [[6, 1], [6, 1]],
']': [[7, 1]], '}': [[2, 5], [7, 1]], ')': [[7, 1], [7, 1]],
'f': [[8, 1]], 'F': [[2, 5], [8, 1]],
'h': [[9, 1]], 'H': [[2, 5], [9, 1]],
'c': [[10, 1]], 'C': [[2, 5], [10, 1]],
'p': [[11, 1]], 'P': [[2, 5], [11, 1]],
'x': [[12, 1]], 'X': [[2, 5], [12, 1]],
'\\': [[13, 1]], '|': [[2, 5], [13, 1]],
'\t': [[0, 2]],
'a': [[1, 2]], 'A': [[2, 5], [1, 2]],
'o': [[2, 2]], 'O': [[2, 5], [2, 2]],
'e': [[3, 2]], 'E': [[2, 5], [3, 2]],
'i': [[4, 2]], 'I': [[2, 5], [4, 2]],
'u': [[5, 2]], 'U': [[2, 5], [5, 2]],
'd': [[8, 2]], 'D': [[2, 5], [8, 2]],
'r': [[9, 2]], 'R': [[2, 5], [9, 2]],
't': [[10, 2]], 'T': [[2, 5], [10, 2]],
'n': [[11, 2]], 'N': [[2, 5], [11, 2]],
's': [[12, 2]], 'S': [[2, 5], [12, 2]],
'=': [[13, 2]], '+': [[2, 5], [13, 2]],
'z': [[1, 3]], 'Z': [[2, 5], [1, 3]],
'q': [[2, 3]], 'Q': [[2, 5], [2, 3]],
'\'': [[3, 3]], '"': [[2, 5], [3, 3]],
',': [[4, 3]], '<': [[2, 5], [4, 3]],
'.': [[5, 3]], '>': [[2, 5], [5, 3]],
'b': [[8, 3]], 'B': [[2, 5], [8, 3]],
'k': [[9, 3]], 'K': [[2, 5], [9, 3]],
'v': [[10, 3]], 'V': [[2, 5], [10, 3]],
'j': [[11, 3]], 'J': [[2, 5], [11, 3]],
'/': [[12, 3]], '?': [[2, 5], [12, 3]],
':': [[4, 4]], ';': [[4, 4], [4, 4]],
'-': [[9, 4]], '_': [[2, 5], [9, 4]],
' ': [[10, 5]],
'\n': [[11, 5]],
## Layered things
# Hungarian
'á': [[9, 5], [1, 2]], 'Á': [[2, 5], [9, 5], [1, 2]],
'ó': [[9, 5], [2, 2]], 'Ó': [[2, 5], [9, 5], [2, 2]],
'ő': [[9, 5], [2, 1]], 'Ő': [[2, 5], [9, 5], [2, 1]],
'ö': [[9, 5], [2, 3]], 'Ö': [[2, 5], [9, 5], [2, 3]],
'é': [[9, 5], [3, 2]], 'É': [[2, 5], [9, 5], [3, 2]],
'ú': [[9, 5], [4, 2]], 'Ú': [[2, 5], [9, 5], [4, 2]],
'ű': [[9, 5], [4, 1]], 'Ű': [[2, 5], [9, 5], [4, 1]],
'ü': [[9, 5], [4, 3]], 'Ü': [[2, 5], [9, 5], [4, 3]],
'í': [[9, 5], [5, 2]], 'Í': [[2, 5], [9, 5], [5, 2]],
}
def lookup_char(layer, ch):
if ch in charmap:
return charmap[ch]
return None
def process_char(layer, ch, out=sys.stdout):
keys = lookup_char(layer, ch)
if not keys:
print ("Unknown char: %s" % ch, file=sys.stderr)
else:
for (c, r) in keys:
print ("KL: col=%d, row=%d, pressed=1, layer=%s" % (r, c, layer), file=out)
print ("KL: col=%d, row=%d, pressed=0, layer=%s" % (r, c, layer), file=out)
def process_file(fn, layer, out=sys.stdout):
with open(fn, "r") as f:
ch = f.read(1)
while ch:
process_char(layer, ch, out)
ch = f.read(1)
if sys.argv[1] == '-':
out='/dev/stdin'
else:
out=sys.argv[1]
if len(sys.argv) >= 2:
layer = 'ADORE'
else:
layer = sys.argv[2]
process_file(out, layer = layer)