left4me/experiments/keyboard/keyboard.rb
mwiegand 010fb5df38
wip
2022-11-19 20:00:51 +01:00

295 lines
5.7 KiB
Ruby
Executable file
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env ruby
# https://developer.valvesoftware.com/wiki/Bind
keys = {
escape: {
title: 'Escape',
keycap: 'ESC',
},
tab: {
title: 'Tabulator',
keycap: '↹',
},
capslock: {
title: 'Capslock',
keycap: '⇪',
},
shift: {
title: 'Shift',
keycap: '⇧',
},
ctrl: {
title: 'Control',
keycap: 'CTL',
},
alt: {
title: 'ALT',
keycap: 'ALT',
},
space: {
title: 'Space',
keycap: 'SPACE',
},
backspace: {
title: 'Backspace',
keycap: '⇦',
},
enter: {
title: 'Enter',
keycap: '↵',
},
semicolon: {
title: 'Semicolon',
keycap: ';',
},
lwin: {
title: 'Left Super',
keycap: '⊞',
},
rwin: {
title: 'Right Super',
keycap: '⊞',
},
apps: {
title: 'Menu',
keycap: '≡',
},
numlock: {
title: 'Numlock',
keycap: 'NUM',
},
scrolllock: {
title: 'Scrollock',
keycap: 'SCR',
},
uparrow: {
title: 'Arrow Up',
keycap: '↑',
},
downarrow: {
title: 'Arrow Down',
keycap: '↓',
},
leftarrow: {
title: 'Arrow Left',
keycap: '←',
},
rightarrow: {
title: 'Arrow Right',
keycap: '→',
},
ins: {
title: 'Insert',
keycap: 'INS',
},
del: {
title: 'Delete',
keycap: '⇨',
},
pgdn: {
title: 'Page Down',
keycap: '⇣',
},
pgup: {
title: 'Page Up',
keycap: '⇡',
},
home: {
title: 'Home',
keycap: '⌂',
},
end: {
title: 'End',
keycap: '⇥',
},
pause: {
title: 'Pause',
keycap: '⏸',
},
kp_end: {
title: 'Keypad 1 (End)',
keycap: '1',
},
kp_downarrow: {
title: 'Keypad 2 (Arrow Down)',
keycap: '2',
},
kp_pgdn: {
title: 'Keypad 3 (Page Down)',
keycap: '3',
},
kp_leftarrow: {
title: 'Keypad 4 (Arrow Left)',
keycap: '4',
},
kp_5: {
title: 'Keypad 5',
keycap: '5',
},
kp_rightarrow: {
title: 'Keypad 6 (Arrow Right)',
keycap: '6',
},
kp_home: {
title: 'Keypad 7 (Home)',
keycap: '7',
},
kp_uparrow: {
title: 'Keypad 8 (Arrow Up)',
keycap: '8',
},
kp_pgup: {
title: 'Keypad 9 (Page Up)',
keycap: '9',
},
kp_enter: {
title: 'Keypad Enter',
keycap: '↵',
},
kp_ins: {
title: 'Keypad 0',
keycap: '0',
},
kp_del: {
title: 'Keypad .',
keycap: '.',
},
kp_slash: {
title: 'Keypad /',
keycap: '/',
},
kp_multiply: {
title: 'Keypad *',
keycap: '*',
},
kp_minus: {
title: 'Keypad -',
keycap: '-',
},
kp_plus: {
title: 'Keypad +',
keycap: '+',
},
mwheeldown: {
title: 'Mousewheel Down',
keycap: '⇟',
},
mwheelup: {
title: 'Mousewheel Up',
keycap: '⇞',
},
mouse1: {
title: 'Mouse 1',
keycap: '🖱1',
},
mouse2: {
title: 'Mouse 2',
keycap: '🖱2',
},
mouse3: {
title: 'Mouse 3',
keycap: '🖱3',
},
mouse4: {
title: 'Mouse 4',
keycap: '🖱4',
},
mouse5: {
title: 'Mouse 5',
keycap: '🖱5',
},
}
%(0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZÄÖÜß,.+-*/#^´).each_char do |char|
keys[char.to_sym] = {
title: char,
'keymap': char,
}
end
(1..12).each do |num|
keys[:"F#{num}"] = {
title: "Function #{num}",
'keymap': "F#{num}",
}
end
keycaps = {
'h1': {
width: 1,
points: '-0.44,-0.44 0.44,-0.44 0.44,0.44 -0.44,0.44',
},
'h1.25': {
width: 1.25,
points: '-0.565,-0.44 0.565,-0.44 0.565,0.44 -0.565,0.44',
},
'h1.5': {
width: 1.5,
points: '-0.69,-0.44 0.69,-0.44 0.69,0.44 -0.69,0.44',
},
'h1.75': {
width: 1.75,
points: '-0.815,-0.44 0.815,-0.44 0.815,0.44 -0.815,0.44',
},
'h2': {
width: 2,
points: '-0.94,-0.44 0.94,-0.44 0.94,0.44 -0.94,0.44',
},
'h2.5': {
width: 2.5,
points: '-1.19,-0.44 1.19,-0.44 1.19,0.44 -1.19,0.44',
},
'h2.75': {
width: 2.75,
points: '-1.315,-0.44 1.315,-0.44 1.315,0.44 -1.315,0.44',
},
'h6.5': {
width: 6.5,
points: '-3.19,-0.44 3.19,-0.44 3.19,0.44 -3.19,0.44',
},
'v2': {
width: 1,
points: '-0.44,-0.44 0.44,-0.44 0.44,1.44 -0.44,1.44',
},
'enter_iso': {
width: 1.5,
points: '-0.69,-0.44 0.69,-0.44 0.69,1.44 -0.44,1.44 -0.44,0.44 -0.69,0.44',
},
}
keyboard = {
0 => 'ESC :1 F1 F2 F3 F4 :.5 F5 F6 F7 F8 :.5 F9 F10 F11 F12 :.25 PNT ROL PAU',
1.25 => '^ 1 2 3 4 5 6 7 8 9 0 ß ´ BACKSP:h2 :.25 INS HOM PUP :.25 NUM / * -',
2.25 => 'TAB:h1.5 Q W E R T Z U I O P Ü + ENT:enter_iso :.25 DEL END PDN :.25 7 8 9 +:v2',
3.25 => 'CAPS:h1.75 A S D F G H J K L Ö Ä # :1.25 :.25 :1 :1 :1 :.25 4 5 6',
4.25 => 'SHIFT:h1.25 < Y X C V B N M , . - SHIFT:h2.75 :.25 :1 ARU :1 :.25 1 2 3 ENT:v2',
5.25 => 'CTL:h1.25 SUP:h1.25 ALT:h1.25 SPACE:h6.5 AGR:h1.25 SUP:h1.25 MENU CTL:h1.25 :.25 ARL ARD ARR :.25 0:h2 DEL'
}
keyboard_keys = []
total_h = 0
total_v = 0
keyboard.each do |row_v, row_text|
row_h = 0
row_text.split.each do |element|
if element.start_with? ':'
row_h += element[1..].to_f
else
key, keycap = element.split(':')
keycap ||= :h1
keyboard_keys.append({
name: key,
keycap: keycap,
x: row_h + keycaps[keycap.to_sym][:width]/2.0,
y: 0.5 + row_v,
})
row_h += keycaps[keycap.to_sym][:width]
end
end
total_h = [total_h, row_h].max
total_v = [total_v, row_v].max
end
require "erb"
html = ERB.new(File.read(File.join(__dir__, 'keyboard.erb'))).result_with_hash({keys: keyboard_keys, total_h: total_h, total_v: total_v+1})
File.write(File.join(__dir__, 'keyboard.html'), html)