Permalink
Branch: master
Find file Copy path
239245e Jun 15, 2018
1 contributor

Users who have contributed to this file

183 lines (148 sloc) 3.88 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('s'), key('i')],
'' => [key('s'), key('e')],
'' => [key('z'), key('e')],
'' => [key('t'), key('e')],
'' => [key('n'), key('a')],
'' => [key('m'), key('o')],
'' => [key('x'), key('y'), key('u')],
'' => [key('w'), key('o')],
'1' => [key('1')],
'?' => [key_with_shift('slash')],
}.freeze
########################################
def main
puts JSON.pretty_generate(
'title' => 'Japanese NICOLA (partial) (rev 2)',
'rules' => [
{
'description' => 'Japanese NICOLA (partial) (rev 2)',
'manipulators' => [
# シフトありから並べること
# ------------------------------
# 左シフト
left_shift_key('a', ''),
left_shift_key('s', ''),
left_shift_key('d', ''),
left_shift_key('f', ''),
left_shift_key('f', ''),
left_shift_key('1', '?'),
# ------------------------------
# 右シフト
right_shift_key('f', ''),
# ------------------------------
# シフトなし
normal_key('a', ''),
normal_key('s', ''),
normal_key('d', ''),
normal_key('f', ''),
normal_key('g', ''),
normal_key('1', '1'),
],
},
]
)
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