Permalink
Branch: master
Find file Copy path
6a62d7b Feb 1, 2019
1 contributor

Users who have contributed to this file

416 lines (338 sloc) 10.3 KB
#!/usr/bin/env ruby
# You can generate json by executing the following command on Terminal.
#
# $ ruby ./example_japanese_nicola.json.rb
#
require 'json'
require_relative '../lib/karabiner.rb'
########################################
# 左シフトのキーコード
LEFT_SHIFT_KEY_CODE = 'spacebar'.freeze
########################################
# 右シフトのキーコード
RIGHT_SHIFT_KEY_CODE = 'lang1'.freeze
########################################
# 有効になる条件
CONDITIONS = [
Karabiner.input_source_if([
{
'input_mode_id' => 'com.apple.inputmethod.Japanese',
},
{
'input_mode_id' => 'com.apple.inputmethod.Japanese.Hiragana',
},
{
'input_mode_id' => 'com.apple.inputmethod.Japanese.Katakana',
},
{
'input_mode_id' => 'com.apple.inputmethod.Japanese.HalfWidthKana',
},
]),
Karabiner.frontmost_application_unless(['loginwindow']),
].freeze
########################################
# ローマ字入力の定義
def key(key_code)
{
'key_code' => key_code,
'repeat' => false,
}
end
def key_with_shift(key_code)
{
'key_code' => key_code,
'modifiers' => [
'left_shift',
],
'repeat' => false,
}
end
ROMAN_MAP = {
'' => [key('a')],
'' => [key('i')],
'' => [key('u')],
'' => [key('e')],
'' => [key('o')],
'' => [key('k'), key('a')],
'' => [key('k'), key('i')],
'' => [key('k'), key('u')],
'' => [key('k'), key('e')],
'' => [key('k'), key('o')],
'' => [key('s'), key('a')],
'' => [key('s'), key('i')],
'' => [key('s'), key('u')],
'' => [key('s'), key('e')],
'' => [key('s'), key('o')],
'' => [key('t'), key('a')],
'' => [key('t'), key('i')],
'' => [key('t'), key('u')],
'' => [key('t'), key('e')],
'' => [key('t'), key('o')],
'' => [key('n'), key('a')],
'' => [key('n'), key('i')],
'' => [key('n'), key('u')],
'' => [key('n'), key('e')],
'' => [key('n'), key('o')],
'' => [key('h'), key('a')],
'' => [key('h'), key('i')],
'' => [key('h'), key('u')],
'' => [key('h'), key('e')],
'' => [key('h'), key('o')],
'' => [key('m'), key('a')],
'' => [key('m'), key('i')],
'' => [key('m'), key('u')],
'' => [key('m'), key('e')],
'' => [key('m'), key('o')],
'' => [key('y'), key('a')],
'' => [key('y'), key('u')],
'' => [key('y'), key('o')],
'' => [key('r'), key('a')],
'' => [key('r'), key('i')],
'' => [key('r'), key('u')],
'' => [key('r'), key('e')],
'' => [key('r'), key('o')],
'' => [key('w'), key('a')],
'' => [key('w'), key('o')],
'' => [key('n'), key('n')],
'' => [key('g'), key('a')],
'' => [key('g'), key('i')],
'' => [key('g'), key('u')],
'' => [key('g'), key('e')],
'' => [key('g'), key('o')],
'' => [key('z'), key('a')],
'' => [key('z'), key('i')],
'' => [key('z'), key('u')],
'' => [key('z'), key('e')],
'' => [key('z'), key('o')],
'' => [key('d'), key('a')],
'' => [key('d'), key('i')],
'' => [key('d'), key('u')],
'' => [key('d'), key('e')],
'' => [key('d'), key('o')],
'' => [key('b'), key('a')],
'' => [key('b'), key('i')],
'' => [key('b'), key('u')],
'' => [key('b'), key('e')],
'' => [key('b'), key('o')],
'' => [key('p'), key('a')],
'' => [key('p'), key('i')],
'' => [key('p'), key('u')],
'' => [key('p'), key('e')],
'' => [key('p'), key('o')],
'' => [key('v'), key('u')],
'' => [key('x'), key('t'), key('u')],
'' => [key('x'), key('y'), key('a')],
'' => [key('x'), key('y'), key('u')],
'' => [key('x'), key('y'), key('o')],
'' => [key('x'), key('a')],
'' => [key('x'), key('i')],
'' => [key('x'), key('u')],
'' => [key('x'), key('e')],
'' => [key('x'), key('o')],
'1' => [key('1')],
'2' => [key('2')],
'3' => [key('3')],
'4' => [key('4')],
'5' => [key('5')],
'6' => [key('6')],
'7' => [key('7')],
'8' => [key('8')],
'9' => [key('9')],
'0' => [key('0')],
'' => [key('comma')],
'' => [key('period')],
'' => [key('hyphen')],
'' => [key_with_shift('slash')],
'' => [key('slash')],
'' => [key_with_shift('equal_sign')],
'' => [key('close_bracket')],
'' => [key('backslash')],
'' => [key_with_shift('8')],
'' => [key_with_shift('9')],
'' => [key_with_shift('close_bracket')],
'' => [key_with_shift('backslash')],
}.freeze
########################################
def main
puts JSON.pretty_generate(
'title' => 'NICOLA for HHKB (rev 1)',
'rules' => [
{
'description' => 'HHKB with keytop',
'manipulators' => [
# シフトありから並べること
# ------------------------------
# 左シフト
#num
left_shift_key('1', ''),
left_shift_key('2', ''),
left_shift_key('3', ''),
left_shift_key('4', ''),
left_shift_key('5', ''),
left_shift_key('6', ''),
left_shift_key('7', ''),
left_shift_key('8', ''),
left_shift_key('9', ''),
left_shift_key('0', ''),
left_shift_key('hyphen', ''),
#upper
left_shift_key('q', ''),
left_shift_key('w', ''),
left_shift_key('e', ''),
left_shift_key('r', ''),
left_shift_key('t', ''),
left_shift_key('y', ''),
left_shift_key('u', ''),
left_shift_key('i', ''),
left_shift_key('o', ''),
left_shift_key('p', ''),
#home
left_shift_key('a', ''),
left_shift_key('s', ''),
left_shift_key('d', ''),
left_shift_key('f', ''),
left_shift_key('g', ''),
left_shift_key('h', ''),
left_shift_key('j', ''),
left_shift_key('k', ''),
left_shift_key('l', ''),
#left_shift_key(';', ''),
#bottom
left_shift_key('z', ''),
left_shift_key('x', ''),
left_shift_key('c', ''),
left_shift_key('v', ''),
left_shift_key('b', ''),
left_shift_key('n', ''),
left_shift_key('m', ''),
left_shift_key('comma', ''),
left_shift_key('period', ''),
left_shift_key('slash', ''),
# ------------------------------
# 右シフト
#numを設定すると、パグが起きる。
#upper
right_shift_key('w', ''),
right_shift_key('e', ''),
right_shift_key('r', ''),
right_shift_key('t', ''),
right_shift_key('y', ''),
right_shift_key('u', ''),
right_shift_key('i', ''),
right_shift_key('o', ''),
right_shift_key('p', ''),
#home
right_shift_key('a', ''),
right_shift_key('s', ''),
right_shift_key('d', ''),
right_shift_key('f', ''),
right_shift_key('g', ''),
right_shift_key('h', ''),
right_shift_key('j', ''),
right_shift_key('k', ''),
right_shift_key('l', ''),
right_shift_key('semicolon', ''),
#bottom
right_shift_key('x', ''),
right_shift_key('c', ''),
right_shift_key('v', ''),
right_shift_key('b', ''),
right_shift_key('n', ''),
right_shift_key('m', ''),
right_shift_key('comma', ''),
right_shift_key('period', ''),
right_shift_key('slash', ''),
# ------------------------------
# シフトなし
#num
normal_key('1', '1'),
normal_key('2', '2'),
normal_key('3', '3'),
normal_key('4', '4'),
normal_key('5', '5'),
normal_key('6', '6'),
normal_key('7', '7'),
normal_key('8', '8'),
normal_key('9', '9'),
normal_key('0', '0'),
#upper
normal_key('q', ''),
normal_key('w', ''),
normal_key('e', ''),
normal_key('r', ''),
normal_key('t', ''),
normal_key('y', ''),
normal_key('u', ''),
normal_key('i', ''),
normal_key('o', ''),
normal_key('open_bracket', ''),
#home
normal_key('a', ''),
normal_key('s', ''),
normal_key('d', ''),
normal_key('f', ''),
normal_key('g', ''),
normal_key('h', ''),
normal_key('j', ''),
normal_key('k', ''),
normal_key('l', ''),
normal_key('semicolon', ''),
#bottom
normal_key('x', ''),
normal_key('c', ''),
normal_key('v', ''),
normal_key('b', ''),
normal_key('n', ''),
normal_key('m', ''),
normal_key('comma', ''),
normal_key('period', ''),
],
},
]
)
end
def normal_key(key, char)
{
'type' => 'basic',
'from' => {
'key_code' => key,
},
'to' => ROMAN_MAP[char],
'conditions' => CONDITIONS,
}
end
def left_shift_key(key, char)
{
'type' => 'basic',
'from' => {
'simultaneous' => [
{
'key_code' => key,
},
{
'key_code' => LEFT_SHIFT_KEY_CODE,
},
],
},
'to' => ROMAN_MAP[char],
'conditions' => CONDITIONS,
}
end
def right_shift_key(key, char)
{
'type' => 'basic',
'from' => {
'simultaneous' => [
{
'key_code' => key,
},
{
'key_code' => RIGHT_SHIFT_KEY_CODE,
},
],
},
'to' => ROMAN_MAP[char],
'conditions' => CONDITIONS,
}
end
main