karabiner 0.3.1 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d0c5b3a09ef8ab46b1340851ef24f67a776a800e
4
- data.tar.gz: 73675efb64d75733c720393755b7f4996e46888f
3
+ metadata.gz: 5f432819fc1b42ec63bc0505b92644bffa27edcb
4
+ data.tar.gz: e68ef48995d6def0b813c4c389183f89f002cc30
5
5
  SHA512:
6
- metadata.gz: a93b691b3c929332a64ff7d7a93654bf742895049dfe3022a073a0c4d8a8a02e4e80705c0926ddf64e8526d031423127e4a6d53406f9ea3d23b5d8ba0ba5e398
7
- data.tar.gz: 377b271a2aee5a4b0e655c90b0a2316a4607f5184786f4522d6004caf3362b54e1c3e9561297c6ffaea92fb539be3298c4e93054b10c2ded135b621f9b9929b6
6
+ metadata.gz: 5e966346719f6afcbdfbdfd606b6b9d807dfa9ace01e5e340c8fc5d962bfebc60461d16c20e0854ac294e635e82f46020621c56f582b8a9024f170321409e6cb
7
+ data.tar.gz: fb23950b2c04ff2cd35dd0b9d8a5bbf6bb17dcf9aade7e6fe97e93525a86101081d14482470e1101f1fdd66b76fe6a3bad166a25caa92a660044953cededac36
@@ -0,0 +1,35 @@
1
+ # Change Log
2
+
3
+ ## [v0.3.1](https://github.com/k0kubun/karabiner-dsl/tree/v0.3.1) (2016-05-17)
4
+ [Full Changelog](https://github.com/k0kubun/karabiner-dsl/compare/v0.3.0...v0.3.1)
5
+
6
+ ## [v0.3.0](https://github.com/k0kubun/karabiner-dsl/tree/v0.3.0) (2015-12-31)
7
+ [Full Changelog](https://github.com/k0kubun/karabiner-dsl/compare/v0.2.1...v0.3.0)
8
+
9
+ **Merged pull requests:**
10
+
11
+ - Can invoke the application of any place [\#5](https://github.com/k0kubun/karabiner-dsl/pull/5) ([elim](https://github.com/elim))
12
+
13
+ ## [v0.2.1](https://github.com/k0kubun/karabiner-dsl/tree/v0.2.1) (2015-08-30)
14
+ [Full Changelog](https://github.com/k0kubun/karabiner-dsl/compare/v0.2.0...v0.2.1)
15
+
16
+ ## [v0.2.0](https://github.com/k0kubun/karabiner-dsl/tree/v0.2.0) (2015-07-08)
17
+ [Full Changelog](https://github.com/k0kubun/karabiner-dsl/compare/v0.1.2...v0.2.0)
18
+
19
+ ## [v0.1.2](https://github.com/k0kubun/karabiner-dsl/tree/v0.1.2) (2015-05-21)
20
+ [Full Changelog](https://github.com/k0kubun/karabiner-dsl/compare/v0.1.1...v0.1.2)
21
+
22
+ **Merged pull requests:**
23
+
24
+ - Add supporting BACKQUOTE [\#4](https://github.com/k0kubun/karabiner-dsl/pull/4) ([cnosuke](https://github.com/cnosuke))
25
+
26
+ ## [v0.1.1](https://github.com/k0kubun/karabiner-dsl/tree/v0.1.1) (2014-11-16)
27
+ [Full Changelog](https://github.com/k0kubun/karabiner-dsl/compare/v0.0.8...v0.1.1)
28
+
29
+ ## [v0.0.8](https://github.com/k0kubun/karabiner-dsl/tree/v0.0.8) (2014-11-16)
30
+ [Full Changelog](https://github.com/k0kubun/karabiner-dsl/compare/v0.1.0...v0.0.8)
31
+
32
+ ## [v0.1.0](https://github.com/k0kubun/karabiner-dsl/tree/v0.1.0) (2014-11-16)
33
+
34
+
35
+ \* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
data/README.md CHANGED
@@ -81,34 +81,44 @@ You have to write "key expression" to specify keys to remap.
81
81
  #### key expression
82
82
 
83
83
  - `a`, `A`, `1`, `;`, `tab`, `Tab`, `space`, `up`, `down`
84
- - any string without `-` will be regarded as single key
85
- - ignore upcase or downcase
86
- - `C-a`, `Ctrl-a`
87
- - regarded as Control + A
88
- - `C-` is a short expression of `Ctrl-`
89
- - `M-a`, `Opt-a`
90
- - regarded as Option + A
91
- - `Shift-a`
92
- - regarded as large A
93
- - if you write just `A`, it will be regarded as small a
94
- - `Cmd-a`
95
- - regarded as Command + A
96
- - `Cmd-Shift-a`
97
- - regarded as Command + Shift + A
98
- - you can use any combination of Ctrl, Opt, Shift, Cmd
84
+ - any string without `-` or `+` will be regarded as a single key
85
+ - strings are case insensitive
86
+ - `Volume Mute`, `Mute`, `Brightness Down`, `Brightness_Down`
87
+ - support system (consumer) keys
88
+ - words could be separated by space ` ` or underscore `_`
89
+ - nil, `nil`, `none`
90
+ - you can drop any key by using nil or the corresponding aliases
91
+
92
+ #### key combination
93
+
94
+ | Key combination | Regarded as | Notes |
95
+ | ---------------------------------------------------------- | --------------------- | ------ |
96
+ | `C-a`, `Ctrl-a`, `C+a`, `Ctrl+a` | Control + A | `C-` is a short alias for `Ctrl-` |
97
+ | `M-a`, `Opt-a`, `Alt-a`, `M+a`, `Opt+a`, `Alt+a` | Option + A | `M-` and `Alt-` are aliases for `Opt-` |
98
+ | `Shift-a`, `Shift+a` | Shift + A (capital A) | if you write just `A`, it will be regarded as small a |
99
+ | `Cmd-a`, `Cmd+a` | Command + A | |
100
+ | `Cmd-Shift-a`, `Cmd+Shift-a`, `Cmd-Shift+a`, `Cmd+Shift+a` | Command + Shift + A | you can use any combination of Ctrl, Opt, Shift, Cmd |
99
101
 
100
102
  #### available single keys
101
103
 
104
+ [Karabiner DSL keycode and alias reference](https://github.com/k0kubun/karabiner-dsl/blob/master/lib/karabiner/key.rb)
105
+
106
+ [Karabiner full keycode reference](https://pqrs.org/osx/karabiner/xml.html#keycode-list)
107
+
102
108
  ```
103
109
  a b c ... x y z
104
110
  0 1 2 ... 7 8 9
111
+
105
112
  F1 F2 ... F11 F12
106
113
  \ [ ] ; ' ` , . / - =
107
114
  Up Down Right Left
108
- space tab delete forward_delete capslock
115
+ Space Tab Delete ... Forward_Delete Esc Capslock
116
+ Mute Volume_Down Volume_Up ... Prev Play Next
117
+
118
+ nil none
109
119
 
110
120
  Ctrl_R Ctrl_L
111
- Opt_R Opt_L
121
+ Opt_R Opt_L Alt_R Alt_L
112
122
  Cmd_R Cmd_L
113
123
  Shift_R Shift_L
114
124
  ```
@@ -1,5 +1,24 @@
1
1
  class Karabiner::Key
2
- KEYCODE_MAP = {
2
+ def self.normalize_input(raw_input)
3
+ if raw_input.match(/^VK_/)
4
+ raw_input
5
+ else
6
+ raw_input = raw_input.tr(' ', '_').tr('+', '-').upcase
7
+ end
8
+ end
9
+
10
+ def self.normalize_and_freeze!(map)
11
+ map.tap do |h|
12
+ h.keys.each { |k| h[normalize_input(k)] = h.delete(k) }
13
+ end
14
+ map.freeze
15
+ end
16
+
17
+ # Karabiner full keycode reference:
18
+ # https://pqrs.org/osx/karabiner/xml.html#keycode-list
19
+ KEYCODE_MAP = normalize_and_freeze!({
20
+ "nil" => "VK_NONE",
21
+ "none" => "VK_NONE",
3
22
  "0" => "KEY_0",
4
23
  "1" => "KEY_1",
5
24
  "2" => "KEY_2",
@@ -33,15 +52,42 @@ class Karabiner::Key
33
52
  "Opt_L" => "OPTION_L",
34
53
  "Cmd_R" => "COMMAND_R",
35
54
  "Cmd_L" => "COMMAND_L",
36
- }.freeze
37
- PREFIX_MAP = {
38
- "C" => "VK_CONTROL",
39
- "Ctrl" => "VK_CONTROL",
40
- "Cmd" => "VK_COMMAND",
41
- "Shift" => "VK_SHIFT",
42
- "M" => "VK_OPTION",
43
- "Opt" => "VK_OPTION",
44
- }.freeze
55
+ "Esc" => "ESCAPE",
56
+ })
57
+ CONSUMER_MAP = normalize_and_freeze!({
58
+ "Brightness Down" => "BRIGHTNESS_DOWN",
59
+ "Brightness Up" => "BRIGHTNESS_UP",
60
+ "Keyboardlight Off" => "KEYBOARDLIGHT_OFF",
61
+ "Keyboardlight Low" => "KEYBOARDLIGHT_LOW",
62
+ "Keyboardlight High" => "KEYBOARDLIGHT_HIGH",
63
+ "Keyboard Light Off" => "KEYBOARDLIGHT_OFF",
64
+ "Keyboard Light Low" => "KEYBOARDLIGHT_LOW",
65
+ "Keyboard Light High" => "KEYBOARDLIGHT_HIGH",
66
+ "Music Prev" => "MUSIC_PREV",
67
+ "Music Play" => "MUSIC_PLAY",
68
+ "Music Next" => "MUSIC_NEXT",
69
+ "Prev" => "MUSIC_PREV",
70
+ "Play" => "MUSIC_PLAY",
71
+ "Next" => "MUSIC_NEXT",
72
+ "Volume Mute" => "VOLUME_MUTE",
73
+ "Volume Down" => "VOLUME_DOWN",
74
+ "Volume Up" => "VOLUME_UP",
75
+ "Mute" => "VOLUME_MUTE",
76
+ "Eject" => "EJECT",
77
+ "Power" => "POWER",
78
+ "Numlock" => "NUMLOCK",
79
+ "Num Lock" => "NUMLOCK",
80
+ "Video Mirror" => "VIDEO_MIRROR",
81
+ })
82
+ PREFIX_MAP = normalize_and_freeze!({
83
+ "C" => "VK_CONTROL",
84
+ "Ctrl" => "VK_CONTROL",
85
+ "Cmd" => "VK_COMMAND",
86
+ "Shift" => "VK_SHIFT",
87
+ "M" => "VK_OPTION",
88
+ "Opt" => "VK_OPTION",
89
+ "Alt" => "VK_OPTION",
90
+ })
45
91
  PREFIX_EXPRESSION = "(#{PREFIX_MAP.keys.map { |k| k + '-' }.join('|')})"
46
92
 
47
93
  def initialize(expression)
@@ -55,6 +101,8 @@ class Karabiner::Key
55
101
  private
56
102
 
57
103
  def key_combination(raw_combination)
104
+ return "KeyCode::VK_NONE" if raw_combination.nil?
105
+ raw_combination = normalize_key_combination(raw_combination)
58
106
  raw_prefixes, raw_key = split_key_combination(raw_combination)
59
107
  return key_expression(raw_key) if raw_prefixes.empty?
60
108
 
@@ -64,14 +112,19 @@ class Karabiner::Key
64
112
 
65
113
  def key_expression(raw_key)
66
114
  case raw_key
67
- when /^(#{KEYCODE_MAP.keys.map { |k| Regexp.escape(k) }.join('|')})$/
115
+ when /^#{Regexp.union(KEYCODE_MAP.keys)}$/
68
116
  "KeyCode::#{KEYCODE_MAP[raw_key]}"
117
+ when /^#{Regexp.union(CONSUMER_MAP.keys)}$/
118
+ "ConsumerKeyCode::#{CONSUMER_MAP[raw_key]}"
69
119
  else
70
- raw_key = raw_key.upcase unless raw_key.match(/^VK_/)
71
120
  "KeyCode::#{raw_key}"
72
121
  end
73
122
  end
74
123
 
124
+ def normalize_key_combination(raw_combination)
125
+ self.class.normalize_input(raw_combination)
126
+ end
127
+
75
128
  def split_key_combination(raw_combination)
76
129
  prefixes = []
77
130
  key = raw_combination.dup
@@ -1,3 +1,3 @@
1
1
  class Karabiner
2
- VERSION = "0.3.1"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -1,34 +1,14 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Karabiner::Key do
4
+ describe ".normalize_input" do
5
+ it { expect(described_class.normalize_input('Cmd+Volume Up')).to eq('CMD-VOLUME_UP') }
6
+ end
7
+
4
8
  describe "#to_s" do
5
9
  EXPECTED_RESULTS = {
6
- "a" => "KeyCode::A",
7
- "b" => "KeyCode::B",
8
- "c" => "KeyCode::C",
9
- "d" => "KeyCode::D",
10
- "e" => "KeyCode::E",
11
- "f" => "KeyCode::F",
12
- "g" => "KeyCode::G",
13
- "h" => "KeyCode::H",
14
- "i" => "KeyCode::I",
15
- "j" => "KeyCode::J",
16
- "k" => "KeyCode::K",
17
- "l" => "KeyCode::L",
18
- "m" => "KeyCode::M",
19
- "n" => "KeyCode::N",
20
- "o" => "KeyCode::O",
21
- "p" => "KeyCode::P",
22
- "q" => "KeyCode::Q",
23
- "r" => "KeyCode::R",
24
- "s" => "KeyCode::S",
25
- "t" => "KeyCode::T",
26
- "u" => "KeyCode::U",
27
- "v" => "KeyCode::V",
28
- "w" => "KeyCode::W",
29
- "x" => "KeyCode::X",
30
- "y" => "KeyCode::Y",
31
- "z" => "KeyCode::Z",
10
+ "nil" => "KeyCode::VK_NONE",
11
+ "none" => "KeyCode::VK_NONE",
32
12
  "A" => "KeyCode::A",
33
13
  "B" => "KeyCode::B",
34
14
  "C" => "KeyCode::C",
@@ -90,6 +70,31 @@ describe Karabiner::Key do
90
70
  "Cmd_L" => "KeyCode::COMMAND_L",
91
71
  "Shift_R" => "KeyCode::SHIFT_R",
92
72
  "Shift_L" => "KeyCode::SHIFT_L",
73
+ "Esc" => "KeyCode::ESCAPE",
74
+
75
+ "Brightness Down" => "ConsumerKeyCode::BRIGHTNESS_DOWN",
76
+ "Brightness Up" => "ConsumerKeyCode::BRIGHTNESS_UP",
77
+ "Keyboardlight Off" => "ConsumerKeyCode::KEYBOARDLIGHT_OFF",
78
+ "Keyboardlight Low" => "ConsumerKeyCode::KEYBOARDLIGHT_LOW",
79
+ "Keyboardlight High" => "ConsumerKeyCode::KEYBOARDLIGHT_HIGH",
80
+ "Keyboard Light Off" => "ConsumerKeyCode::KEYBOARDLIGHT_OFF",
81
+ "Keyboard Light Low" => "ConsumerKeyCode::KEYBOARDLIGHT_LOW",
82
+ "Keyboard Light High" => "ConsumerKeyCode::KEYBOARDLIGHT_HIGH",
83
+ "Music Prev" => "ConsumerKeyCode::MUSIC_PREV",
84
+ "Music Play" => "ConsumerKeyCode::MUSIC_PLAY",
85
+ "Music Next" => "ConsumerKeyCode::MUSIC_NEXT",
86
+ "Prev" => "ConsumerKeyCode::MUSIC_PREV",
87
+ "Play" => "ConsumerKeyCode::MUSIC_PLAY",
88
+ "Next" => "ConsumerKeyCode::MUSIC_NEXT",
89
+ "Volume Mute" => "ConsumerKeyCode::VOLUME_MUTE",
90
+ "Volume Down" => "ConsumerKeyCode::VOLUME_DOWN",
91
+ "Volume Up" => "ConsumerKeyCode::VOLUME_UP",
92
+ "Mute" => "ConsumerKeyCode::VOLUME_MUTE",
93
+ "Eject" => "ConsumerKeyCode::EJECT",
94
+ "Power" => "ConsumerKeyCode::POWER",
95
+ "Numlock" => "ConsumerKeyCode::NUMLOCK",
96
+ "Num Lock" => "ConsumerKeyCode::NUMLOCK",
97
+ "Video Mirror" => "ConsumerKeyCode::VIDEO_MIRROR",
93
98
  }.freeze
94
99
 
95
100
  it "converts single key expression as expected" do
@@ -112,5 +117,15 @@ describe Karabiner::Key do
112
117
  expect(described_class.new("#{prefix1}-#{prefix2}-#{key}").to_s).to eq("#{keycode}, #{vk1} | #{vk2}")
113
118
  end
114
119
  end
120
+
121
+ it "converts key expression in case-insensitive manner" do
122
+ EXPECTED_RESULTS.each do |expression, result|
123
+ expect(described_class.new(expression.swapcase).to_s).to eq(result)
124
+ end
125
+ end
126
+
127
+ it "accepts nil class as key expression" do
128
+ expect(described_class.new(nil).to_s).to eq("KeyCode::VK_NONE")
129
+ end
115
130
  end
116
131
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: karabiner
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Takashi Kokubun
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-17 00:00:00.000000000 Z
11
+ date: 2016-07-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -92,6 +92,7 @@ files:
92
92
  - ".gitignore"
93
93
  - ".rspec"
94
94
  - ".travis.yml"
95
+ - CHANGELOG.md
95
96
  - Gemfile
96
97
  - LICENSE.txt
97
98
  - README.md