Convert the output of http://www.keyboard-layout-editor.com/ to exact offsets in inches and mm.
Created
August 6, 2020 13:57
-
-
Save BalzGuenat/0c364e8d8a6469a17f7a166b182f5eba to your computer and use it in GitHub Desktop.
kle2offset
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
["~\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