Skip to content

Instantly share code, notes, and snippets.

@BalzGuenat
Created August 6, 2020 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BalzGuenat/0c364e8d8a6469a17f7a166b182f5eba to your computer and use it in GitHub Desktop.
Save BalzGuenat/0c364e8d8a6469a17f7a166b182f5eba to your computer and use it in GitHub Desktop.
kle2offset
var kle = require("@ijprest/kle-serial");
var fs = require('fs');
const INVERT_Y = true;
const origin_inch = {x:0, y:0};
var inputFile = fs.readFileSync('Split60.json', 'utf8');
var kb = kle.Serial.parse(inputFile);
for (var i = 0; i < kb.keys.length; i++) {
var k = kb.keys[i];
// k.cx is the center of the key, in units
k.cx = k.x + k.width / 2 - 0.5;
k.cy = k.y + k.height / 2 - 0.5;
if (INVERT_Y) {
k.cy = -k.cy;
}
k.xinch = (origin_inch.x + k.cx * 0.75).toFixed(4);
k.yinch = (origin_inch.y + k.cy * 0.75).toFixed(4);
k.xmm = (k.cx * 19.05).toFixed(3);
k.ymm = (k.cy * 19.05).toFixed(3);
console.log(`${k.labels[0]} -> ${k.xinch}' / ${k.xmm}mm`);
}
[
["~\n`","!\n1","@\n2","#\n3","$\n4","%\n5","^\n6","&\n7","*\n8","(\n9",")\n0","_\n-","+\n=",{w:2},"Backspace"],
[{w:1.5},"Tab","Q","W","E","R","T","Y","U","I","O","P","{\n[","}\n]",{w:1.5},"|\n\\"],
[{w:1.75},"Caps Lock","A","S","D","F","G","H","J","K","L",":\n;","\"\n'",{w:2.25},"Enter"],
[{w:2.25},"Shift","Z","X","C","V","B","N","M","<\n,",">\n.","?\n/",{w:1.75},"Shift","Fn"],
[{w:1.25},"Ctrl",{w:1.25},"Win",{w:1.25},"Alt",{w:2.75},"",{w:1.25},"Fn",{w:2.25},"",{w:1.25},"Alt",{w:1.25},"Win",{w:1.25},"Menu",{w:1.25},"Ctrl"]
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment