Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workaround for CJKV input sources switching issue #1602

Closed
gxfxyz opened this issue Oct 14, 2018 · 9 comments
Closed

Workaround for CJKV input sources switching issue #1602

gxfxyz opened this issue Oct 14, 2018 · 9 comments
Labels

Comments

@gxfxyz
Copy link

gxfxyz commented Oct 14, 2018

As you know, the TISSelectInputSource input source switching API still has the bug that sometimes it will fail to switch some CJKV (Chinese, Japanese, Korean, Vietnamese) input sources (only menubar icon changed).

screen shot 2018-10-13 at 15 24 37

Kawa has implemented a workaround to solve this issue:

  • Select a target input source
  • If the source is CJKV
    • Switch to the first non-CJKV input source
    • Return to the target input source by sending Select the previous input source shortcut

I've tested Kawa, and it works great without the issue.

Could you consider adapt this workaround to Karabiner-Elements? It would be really helpful to many CJKV users.

Thank you so much for your awesome project!

Related issues:

References:

@stale
Copy link

stale bot commented Dec 13, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Dec 13, 2018
@stale stale bot closed this as completed Dec 21, 2018
@oklahomer
Copy link

I'm experiencing the same issue.
The good old Cmd + Space works good, but my Mac sometimes fails to do so when I try to switch input source with a customized shortcut I defined with Karabiner Elements. My setting goes like below:

                    {
                        "description": "Use left or right command key to select input source",
                        "manipulators": [
                            {
                                "from": {
                                    "key_code": "left_command",
                                    "modifiers": {
                                        "optional": [
                                            "any"
                                        ]
                                    }
                                },
                                "to": [
                                    {
                                        "key_code": "left_command"
                                    }
                                ],
                                "to_if_alone": [
                                    {
                                        "select_input_source": {
                                            "input_source_id": "^com\\.apple\\.keylayout\\.US$"
                                        }
                                    }
                                ],
                                "type": "basic"
                            },
                            {
                                "from": {
                                    "key_code": "right_command",
                                    "modifiers": {
                                        "optional": [
                                            "any"
                                        ]
                                    }
                                },
                                "to": [
                                    {
                                        "key_code": "right_command"
                                    }
                                ],
                                "to_if_alone": [
                                    {
                                        "select_input_source": {
                                            "input_source_id": "^com\\.google\\.inputmethod\\.Japanese\\.base$"
                                        }
                                    }
                                ],
                                "type": "basic"
                            }
                        ]
                    },

Switching from ja to en always works; while en to ja sometimes fails even though the indicator on menubar and the variables on Karabiner ElementViewer indicate the input source is successfully switched. This behavior looks pretty much similar to the one described in tekezo/Karabiner#308 (comment) as mentioned by @gxfxyz. Karabiner Elements is my favorite so it would be nice if this is somehow fixed or a workaround is found.

@gxfxyz
Copy link
Author

gxfxyz commented Dec 22, 2018

Hi @oklahomer, I don't think this issue will be fixed in the near future as it's a long-existing macOS bug and Kawa's workaround is not fully reliable.

I have similar need as you to use command keys for switching between input sources. My current workaround is:

  1. Bind F18 to "Select the previous input source" in System Preferences/Keyboard/Shortcuts/Input Sources.

screen shot 2018-12-21 at 15 08 42

  1. Let Karabiner-Elements use F18 to change input source based on conditions:
{
    "description": "Tap Command_L (⌘) → switch input source to English (F18)",
    "manipulators": [
        {
            "conditions": [
                {
                    "input_sources": [
                        {
                            "language": "en"
                        }
                    ],
                    "type": "input_source_unless"
                }
            ],
            "from": {
                "key_code": "left_command",
                "modifiers": {
                    "optional": [
                        "caps_lock"
                    ]
                }
            },
            "to": [
                {
                    "key_code": "left_command",
                    "lazy": true
                }
            ],
            "to_if_alone": [
                {
                    "key_code": "f18"
                }
            ],
            "to_if_held_down": [
                {
                    "key_code": "left_command"
                }
            ],
            "type": "basic"
        }
    ]
},
{
    "description": "Tap Command_R (⌘) → switch input source to Chinese (F18)",
    "manipulators": [
        {
            "conditions": [
                {
                    "input_sources": [
                        {
                            "language": "zh-Hans"
                        }
                    ],
                    "type": "input_source_unless"
                }
            ],
            "from": {
                "key_code": "right_command",
                "modifiers": {
                    "optional": [
                        "caps_lock"
                    ]
                }
            },
            "to": [
                {
                    "key_code": "right_command",
                    "lazy": true
                }
            ],
            "to_if_alone": [
                {
                    "key_code": "f18"
                }
            ],
            "to_if_held_down": [
                {
                    "key_code": "right_command"
                }
            ],
            "type": "basic"
        }
    ]
},

It only works if you only use two input sources. Despite that, this workaround is quite reliable as I've been using it for a while. Hope this may help.

@laishulu
Copy link

@tekezo
Copy link
Member

tekezo commented Mar 29, 2020

Karabiner-Elements and emacs use TISSelectInputSource API which is the only API we can switch input source.
The TISSelectInputSource works properly for text area of the own app, but it does not for another process text area.
Emacs's mac-select-input-source does not face this problem because of such API behavior.

@YOnoda
Copy link

YOnoda commented Oct 5, 2020

Anyone knows any workaround for more than two input source, in particular switching between CJKV? @gxfxyz ‘s solution works only when you use two.

@rudders2013
Copy link

Anyone knows any workaround for more than two input source, in particular switching between CJKV? @gxfxyz ‘s solution works only when you use two.

I also met this problem last night. Luckily I find a simple solution today.
see here: https://github.com/rudders2013/rudders2013.github.io/blob/main/A%20simple%20solution%20to%20solve%20the%20%22CJK%20input%20method%20switching%22%20problem%20in%20Karabiner

Sample above shows switching between 4 input methods(简体中文双拼/简体中文五笔/繁体中文双拼/英文切换.)

@rudders2013
Copy link

rudders2013 commented May 31, 2022

It seems just a "refresh" problem. I find a simple refreshing solution by so called "Chinese/English Switch" printed on my CapsLock Key after switching input method.

@rudders2013
Copy link

rudders2013 commented May 31, 2022

I'm not sure if the other versions of macbook have this switching feature.
image

"Chinese/English Switch" printed on CapsLock Key:
image

Here is the detail info of mine(publish in Mainland China):
image

Karabiner version:
image

A shake will happen in the input method icon when switching.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants