yqrashawn / GokuRakuJoudo

config karabiner with ease
GNU General Public License v3.0
1.16k stars 121 forks source link

Mapping a key to a sequence of keys #116

Closed adept587 closed 3 years ago

adept587 commented 3 years ago

How to Mapping a key to a sequence of keys, for example Cmd+A -> Cmd+B, Space, C ?

yqrashawn commented 3 years ago
{:des "Cmd+A -> Cmd+B, Space, C"
 :rules [; [<from> <to>]
         [:!Ca [:!Cb :spacebar :c]]}
adept587 commented 3 years ago

Thanks for your fast reply !

I try to Toggle VSCode, and force input method to ABC after open or hide VSCode.

Try sequence keys without changing input method :

{:des "== Launcher Mode [tab]"
        :rules [ :tab-mode
            [:c [:open-en "/Applications/Visual Studio Code.app"] :!VSCode]
            [:c [:a :!Ch] :VSCode]
]}

Press Tab + C in VSCode, It works to type a then Command-H (Hide VSCode)

BUT …

1st try : define input-abc as :templates

:templates {
  :input-abc "open /Users/jasonshih/MyScript/InputABC.app"
}
{:des "== Launcher Mode [tab]"
        :rules [ :tab-mode
            [:c [:open-en "/Applications/Visual Studio Code.app"] :!VSCode] 
            [:c [:input-abc :!Ch] :VSCode]
]}

Press Tab + C in VSCode, It changes the input-method to ABC, but doesn’t Hide VSCode

2nd try : define select-abc as :tos

:tos {
  :select_abc {:select_input_source
         {:input_source_id "^com\\.apple\\.keylayout\\.ABC$"}}
}
{:des "== Launcher Mode [tab]"
        :rules [ :tab-mode
            [:c [:open-en "/Applications/Visual Studio Code.app"] :!VSCode] 
            [:c [:select_abc :!Ch] :VSCode]
]}

It doesn’t work ! Press Tab + C in VSCode, it just type a c in VSCode.

yqrashawn commented 3 years ago

You can put multiple to into the same vector

[:c [:a :b]] means when press c, insert a then b

try [:c [[:open-en "/Applications/Visual Studio Code.app"] [:input-abc :!Ch]] :!VSCode]

By the way, I occasionally find that karabiner won't change my input method correctly. So I use an app called 自动切换输入法, which can automatically change the input method depends on currently focused app.

You can find it on app store https://apps.apple.com/cn/app/%E8%87%AA%E5%8A%A8%E5%88%87%E6%8D%A2%E8%BE%93%E5%85%A5%E6%B3%95/id1470350547?mt=12. It's free. Though I'm not sure if it's on the app store in other country.

adept587 commented 3 years ago

Thanks for your reply !

try [:c [[:open-en "/Applications/Visual Studio Code.app"] [:input-abc :!Ch]] :!VSCode]

I have tried many combinations, following codes work well in :tab-mode

 [:c [[:open "/Applications/Visual Studio Code.app"] [:input-abc]] :!VSCode]
 [:c [[:input-abc] :!Ch] :VSCode]

also found both [:c [:input-abc :!Ch]] & `[:c [[:input-abc] [:!Ch]]] NOT work.

[:c [[:select_abc] :!Ch] :VSCode] NOT work either.

for ref.

:templates {
  :input-abc "open /Users/jasonshih/MyScript/InputABC.app"
}
:tos {
  :select_abc {:select_input_source
         {:input_source_id "^com\\.apple\\.keylayout\\.ABC$"}}
}