This repository has been archived by the owner on Jan 2, 2023. It is now read-only.
forked from Vonng/Capslock
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9e3f96c
commit a642df1
Showing
2 changed files
with
356 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,194 @@ | ||
#!/usr/bin/env ruby | ||
|
||
# You can generate json by executing the following command on Terminal. | ||
# | ||
# $ ruby ./caps_lock.json.rb | ||
# | ||
|
||
require 'json' | ||
require_relative '../lib/karabiner.rb' | ||
|
||
def main | ||
puts JSON.pretty_generate( | ||
'title' => 'Change caps_lock key (rev 4)', | ||
'rules' => [ | ||
{ | ||
'description' => 'Change caps_lock key to command+control+option+shift if pressed with other keys', | ||
'manipulators' => [ | ||
{ | ||
'type' => 'basic', | ||
'from' => { | ||
'key_code' => 'caps_lock', | ||
'modifiers' => Karabiner.from_modifiers(nil, ['any']), | ||
}, | ||
'to' => [ | ||
{ | ||
'key_code' => 'left_shift', | ||
'modifiers' => %w[ | ||
left_command left_control left_option | ||
], | ||
}, | ||
], | ||
'to_if_alone' => [ | ||
{ | ||
'hold_down_milliseconds' => 100, | ||
'key_code' => 'caps_lock', | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
{ | ||
'description' => 'Change caps_lock key to command+control+option+shift. (Post escape key when pressed alone)', | ||
'manipulators' => [ | ||
{ | ||
'type' => 'basic', | ||
'from' => { | ||
'key_code' => 'caps_lock', | ||
'modifiers' => Karabiner.from_modifiers(nil, ['any']), | ||
}, | ||
'to' => [ | ||
{ | ||
'key_code' => 'left_shift', | ||
'modifiers' => %w[ | ||
left_command left_control left_option | ||
], | ||
}, | ||
], | ||
'to_if_alone' => [ | ||
{ | ||
'key_code' => 'escape', | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
{ | ||
'description' => 'Change caps_lock key to command+control+option+shift. (Post f19 key when pressed alone)', | ||
'manipulators' => [ | ||
{ | ||
'type' => 'basic', | ||
'from' => { | ||
'key_code' => 'caps_lock', | ||
'modifiers' => Karabiner.from_modifiers(nil, ['any']), | ||
}, | ||
'to' => [ | ||
{ | ||
'key_code' => 'left_shift', | ||
'modifiers' => %w[ | ||
left_command left_control left_option | ||
], | ||
}, | ||
], | ||
'to_if_alone' => [ | ||
{ | ||
'key_code' => 'f19', | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
{ | ||
'description' => 'Change caps_lock key to command+control+option+shift. (Use shift+caps_lock as caps_lock)', | ||
'manipulators' => [ | ||
{ | ||
'type' => 'basic', | ||
'from' => { | ||
'key_code' => 'caps_lock', | ||
'modifiers' => Karabiner.from_modifiers(['shift'], ['caps_lock']), | ||
}, | ||
'to' => [ | ||
{ | ||
'key_code' => 'caps_lock', | ||
}, | ||
], | ||
}, | ||
{ | ||
'type' => 'basic', | ||
'from' => { | ||
'key_code' => 'caps_lock', | ||
'modifiers' => Karabiner.from_modifiers(nil, ['any']), | ||
}, | ||
'to' => [ | ||
{ | ||
'key_code' => 'left_shift', | ||
'modifiers' => %w[ | ||
left_command left_control left_option | ||
], | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
{ | ||
'description' => 'Change caps_lock to control if pressed with other keys, to escape if pressed alone.', | ||
'manipulators' => [ | ||
{ | ||
'type' => 'basic', | ||
'from' => { | ||
'key_code' => 'caps_lock', | ||
'modifiers' => Karabiner.from_modifiers(nil, ['any']), | ||
}, | ||
'to' => [ | ||
{ | ||
'key_code' => 'left_control', | ||
}, | ||
], | ||
'to_if_alone' => [ | ||
{ | ||
'key_code' => 'escape', | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
{ | ||
'description' => 'Change caps_lock to control if pressed with other keys. (rev 2)', | ||
'manipulators' => [ | ||
{ | ||
'type' => 'basic', | ||
'from' => { | ||
'key_code' => 'caps_lock', | ||
'modifiers' => Karabiner.from_modifiers(nil, ['any']), | ||
}, | ||
'to' => [ | ||
{ | ||
'key_code' => 'left_control', | ||
}, | ||
], | ||
'to_if_alone' => [ | ||
{ | ||
'key_code' => 'caps_lock', | ||
'hold_down_milliseconds' => 500, | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
{ | ||
'description' => 'Disable caps_lock delay (rev 1)', | ||
'manipulators' => [ | ||
{ | ||
'type' => 'basic', | ||
'from' => { | ||
'key_code' => 'caps_lock', | ||
'modifiers' => Karabiner.from_modifiers(nil, ['any']), | ||
}, | ||
'to' => [ | ||
{ | ||
'key_code' => 'caps_lock', | ||
'hold_down_milliseconds' => 200, | ||
}, | ||
# Put vk_none in order to ensure both caps_lock key_down and key_up events are fired at physical key down. | ||
{ | ||
'key_code' => 'vk_none', | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
] | ||
) | ||
end | ||
|
||
main |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
#!/usr/bin/env ruby | ||
|
||
require 'json' | ||
require_relative '../lib/karabiner.rb' | ||
|
||
def main | ||
puts JSON.pretty_generate( | ||
"title" => "Vi Mode (rev 5)", | ||
"rules" => [ | ||
{ | ||
"description" => "Vi Mode [S as Trigger Key]", | ||
"manipulators" => generate_vi_mode("s"), | ||
# If you want to use other trigger keys for vi mode, just change this above line and run | ||
# | ||
# $ make | ||
# | ||
# in Terminal to generate your new JSON file at docs/json/vi_mode.json. | ||
# | ||
# Copy it to ~/.config/karabiner/assets/complex_modifications then you can enable it in Karabiner-Elements. | ||
# | ||
# Modifier keys such as "command", "option" or "control" cannot be used here. | ||
}, | ||
{ | ||
"description" => "Vi Mode [D as Trigger Key]", | ||
"manipulators" => generate_vi_mode("d"), | ||
}, | ||
{ | ||
"description" => "Vi Visual Mode", | ||
"manipulators" => generate_vi_visual_mode("v"), | ||
}, | ||
], | ||
) | ||
end | ||
|
||
def generate_vi_mode(trigger_key) | ||
[ | ||
generate_vi_mode_single_rule("j", "down_arrow", [], trigger_key), | ||
generate_vi_mode_single_rule("k", "up_arrow", [], trigger_key), | ||
generate_vi_mode_single_rule("h", "left_arrow", [], trigger_key), | ||
generate_vi_mode_single_rule("l", "right_arrow", [], trigger_key), | ||
generate_vi_mode_single_rule("f", "fn", [], trigger_key), | ||
generate_vi_mode_single_rule("b", "left_arrow", ["left_option"], trigger_key), | ||
generate_vi_mode_single_rule("w", "right_arrow", ["left_option"], trigger_key), | ||
generate_vi_mode_single_rule("0", "a", ["left_control"], trigger_key), | ||
generate_vi_mode_single_rule("4", "e", ["left_control"], trigger_key), | ||
].flatten | ||
end | ||
|
||
def generate_vi_visual_mode(trigger_key) | ||
[ | ||
generate_vi_visual_mode_single_rule("j", "down_arrow", ["left_shift"], trigger_key), | ||
generate_vi_visual_mode_single_rule("k", "up_arrow", ["left_shift"], trigger_key), | ||
generate_vi_visual_mode_single_rule("h", "left_arrow", ["left_shift"], trigger_key), | ||
generate_vi_visual_mode_single_rule("l", "right_arrow", ["left_shift"], trigger_key), | ||
generate_vi_visual_mode_single_rule("b", "left_arrow", ["left_shift", "left_option"], trigger_key), | ||
generate_vi_visual_mode_single_rule("w", "right_arrow", ["left_shift", "left_option"], trigger_key), | ||
generate_vi_visual_mode_single_rule("0", "left_arrow", ["left_shift", "left_command"], trigger_key), | ||
generate_vi_visual_mode_single_rule("4", "right_arrow", ["left_shift", "left_command"], trigger_key), | ||
generate_vi_visual_mode_single_rule("open_bracket", "up_arrow", ["left_shift", "left_option"], trigger_key), | ||
generate_vi_visual_mode_single_rule("close_bracket", "down_arrow", ["left_shift", "left_option"], trigger_key), | ||
].flatten | ||
end | ||
|
||
def generate_vi_mode_single_rule(from_key_code, to_key_code, to_modifier_key_code_array, trigger_key) | ||
[ | ||
{ | ||
"type" => "basic", | ||
"from" => { | ||
"key_code" => from_key_code, | ||
"modifiers" => { "optional" => ["any"] }, | ||
}, | ||
"to" => [ | ||
{ | ||
"key_code" => to_key_code, | ||
"modifiers" => to_modifier_key_code_array | ||
}, | ||
], | ||
"conditions" => [ | ||
Karabiner.variable_if('vi_mode', 1), | ||
] | ||
}, | ||
|
||
{ | ||
"type" => "basic", | ||
"from" => { | ||
"simultaneous" => [ | ||
{ "key_code" => trigger_key }, | ||
{ "key_code" => from_key_code }, | ||
], | ||
"simultaneous_options" => { | ||
"key_down_order" => "strict", | ||
"key_up_order" => "strict_inverse", | ||
"detect_key_down_uninterruptedly" => true, | ||
"to_after_key_up" => [ | ||
Karabiner.set_variable("vi_mode", 0), | ||
], | ||
}, | ||
"modifiers" => { "optional" => ["any"] }, | ||
}, | ||
"to" => [ | ||
Karabiner.set_variable("vi_mode", 1), | ||
{ | ||
"key_code" => to_key_code, | ||
"modifiers" => to_modifier_key_code_array | ||
} | ||
] | ||
} | ||
] | ||
end | ||
|
||
def generate_vi_visual_mode_single_rule(from_key_code, to_key_code, to_modifier_key_code_array, trigger_key) | ||
[ | ||
{ | ||
"type" => "basic", | ||
"from" => { | ||
"key_code" => from_key_code, | ||
"modifiers" => { "optional" => ["any"] }, | ||
}, | ||
"to" => [ | ||
{ | ||
"key_code" => to_key_code, | ||
"modifiers" => to_modifier_key_code_array | ||
}, | ||
], | ||
"conditions" => [ | ||
Karabiner.variable_if("vi_visual_mode", 1), | ||
] | ||
}, | ||
|
||
{ | ||
"type" => "basic", | ||
"from" => { | ||
"simultaneous" => [ | ||
{ "key_code" => trigger_key }, | ||
{ "key_code" => from_key_code }, | ||
], | ||
"simultaneous_options" => { | ||
"key_down_order" => "strict", | ||
"key_up_order" => "strict_inverse", | ||
"detect_key_down_uninterruptedly" => true, | ||
"to_after_key_up" => [ | ||
Karabiner.set_variable("vi_visual_mode", 0), | ||
], | ||
}, | ||
"modifiers" => { "optional" => ["any"] }, | ||
}, | ||
"to" => [ | ||
Karabiner.set_variable("vi_visual_mode", 1), | ||
{ | ||
"key_code" => to_key_code, | ||
"modifiers" => to_modifier_key_code_array, | ||
}, | ||
], | ||
"conditions" => [ | ||
Karabiner.frontmost_application_unless(["terminal", "vi"]), | ||
] | ||
} | ||
] | ||
end | ||
|
||
|
||
main() |