Mac third-party input method How to change the CAPS LOCK key to the Input method switch key

Source: Internet
Author: User
Tags modifier

mac third-party input method How to change the CAPS LOCK key to the Input method switch key

According to my personal habits, I finally decided to change the CAPS LOCK key to the Input method switch key, because as a Chinese input method switch is one of the most used shortcut keys, another reason is that the key on the indicator can also be used as an input indicator, it is perfect.

Change Key Bindings

Turn on System Preferences-keyboard-keyboard-modifier keys, set the Caps Lock key to "no action"

Download Seil (Conscience software, conscience author), after opening the Caps Lock key is mapped to key Code 80 (or another nonexistent key, 80 represents F19)

Turn on System Preferences-keyboard-shortcut-input source, set the shortcut key to switch input method to F19 (click Caps Lock after selecting)

done! But now the problem is: Caps locked lights will never light, this is not beautiful! We hope that the LED will also change to be able to indicate the input method state, that is, in the English state is not bright, in Pinyin/Wubi and other input method state light. Google discovered that OS X provides the underlying API for controlling keyboard lights, which can be controlled manually, as detailed in Maclight. It was a good deal, so I tried the following solutions in turn:

Write a Shell script to switch the input method (through AppleScript analog keystroke) + switch led state, create a new "service" by Automator, and then bind the CAPS LOCK key to run the script. But after testing found too much delay (~200ms), give up.

With Objective-c write a call to the underlying API program to switch input method (through the Tisselectinputsource Series API) + switch led state, found that the call API switching input method after the need to switch to the next input window will be effective, and the delay is still very large, give up.

Use Objective-c to write a background application, through the Nsdistributednotificationcenter to receive input method change events, according to the status change led. Science!

Finally, this scientific approach was adopted. Of course, this background application only needs to be the command line application can be, through the launchctl, such as the boot can start automatically. However, because of obsessive-compulsive disorder (easy to start, exit, easy to add as a login to start) or write the occupation in the status bar application, and named Imlight, the following figure:

Update for MacOS Sierra

After upgrading MacOS Sierra, Seil is not working properly (Imlight does not affect), see this Github on issue, and because it is a major change in the system interface, hurry may not have a repair update.

It was also mentioned in Issue that another project for Sierra that the author was developing could be used karabiner-elements, but this project has a few questions for me:

Conflict with imlight (although not necessarily his problem, but I do not know how to fix ...)

Will invalidate modifier key settings for multiple keyboards in System preferences (such as the inability to swap alt and ⌘ on an external keyboard), which the author says cannot be repaired

Another solution is to set the Caps Lock to Ctrl (or otherwise) in System Preferences, and then use other software remapping, such as keyboard Maestro (change Caps Lock, which requires kernel-level modification, and listens to the CTRL key. It's very simple). I use the free Hammerspoon to achieve:

Local M = {}

Local events = Hs.eventtap.event.types

M.log = hs.logger.new (' caps_remap ', ' info ')

M.last_flags_1 = {}

M.last_flags_0 = {}

M.last_time_1 = 0

M.last_time_0 = 0

M.timeout = 0.15

M.key = "Ctrl"

M.action = function () Hs.eventtap.keyStroke ({}, "F19") end

Local function _dict_has_no_other_key (DIC)

For k,v in pairs (DIC) do

If k ~= M.key then

return False

End

End

return True

End

function M.event_callback (e)

Local Typ = E:gettype ()

Local code = E:getkeycode ()

Local flags = E:getflags ()

Local now = Hs.timer.secondsSinceEpoch ()

If _dict_has_no_other_key (flags) and not Flags[m.key]

and _dict_has_no_other_key (M.LAST_FLAGS_0) and M.last_flags_0[m.key]

and _dict_has_no_other_key (m.last_flags_1) and not M.last_flags_1[m.key]

and Now-m.last_time_0 < M.timeout

Then

M.LOG.I ("Fire caps action")

If M.action Then

M.action ()

End

End

M.last_flags_1 = M.last_flags_0

M.LAST_FLAGS_0 = Flags

M.last_time_1 = M.last_time_0

M.last_time_0 = Now

return False

End

function M.init (options)

If Options.key Then

M.key = Options.key

End

If Options.timeout Then

M.timeout = Options.timeout

End

If Options.action Then

M.action = Options.action

End

M.watcher = Hs.eventtap.new ({events.flagschanged}, M.event_callback)

M.watcher:start ()

End

Return M

The

Quick Ctrl (that is, Caps Lock) triggers the F19, and other key combinations that contain CTRL do not meet the requirements.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.