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

hs.keycodes.currentSourceID() sometime doesn't work #1429

Open
dcrozz opened this issue May 17, 2017 · 5 comments
Open

hs.keycodes.currentSourceID() sometime doesn't work #1429

dcrozz opened this issue May 17, 2017 · 5 comments

Comments

@dcrozz
Copy link

dcrozz commented May 17, 2017

System: 10.11.6 (15G1421)

Hi, I love hammerspoon and I am so surprised that it can switch the input method.

The intent is simple, opt + cmd + space to switch between Chinese and English and opt + cmd + j to switch between Japanese and English. But sometime only the icon in input method menu changed (shows the Chinese input is selected) while only English can be input.

What is weird is that this seems to never happen in the hammerspoon console, while when it happens in Firefox, lose the focus on the textbox and get the focus again can solve the problem. The problem is more likely to happen in MacVim and Wechat as I tested.

Also, the candidate window won't disappear when switch the input method by hs.keycodes.currentSourceID(), which looks wired.

hs.hotkey.bind({"cmd","alt"}, 'space', function()
	if hs.keycodes.currentMethod() == nil then
		hs.keycodes.currentSourceID('com.apple.inputmethod.SCIM.ITABC')
	else
		hs.keycodes.currentSourceID("com.apple.keylayout.US")
	end
end)
hs.hotkey.bind({"cmd","alt"}, 'j', function()
	if hs.keycodes.currentMethod() == nil then
		hs.keycodes.currentSourceID('com.apple.inputmethod.Kotoeri.Japanese')
	else
		hs.keycodes.currentSourceID("com.apple.keylayout.US")
	end
end)
@cmsj
Copy link
Member

cmsj commented May 17, 2017

I'm sorry to say that I am fairly unfamiliar with how input methods work, but I wonder if you've looked at using hs.keycodes.setMethod() and hs.keycodes.setLayout() rather than doing everything with currentSourceID()?

@dcrozz
Copy link
Author

dcrozz commented May 17, 2017

The problem still happens when I modify the code to hs.keycodes.setMethod() and hs.keycodes.setLayout(), whether the commented code or the uncommented one doesn't work.

It is interesting that I found that only in the hs console will the candidate window disappear when switching the input method with hs, which is just like how the system input method switching hot key does. All the other application such as MacVim, Firefox, Chrome, Sublime Text fails.

What is the magic of hs console

hs.hotkey.bind({"cmd","alt"}, 'space', function()
	if hs.keycodes.currentMethod() == nil then
		-- hs.keycodes.currentSourceID('com.apple.inputmethod.SCIM.ITABC')
		hs.keycodes.setMethod('Pinyin - Simplified')
	else
		hs.keycodes.setLayout('U.S.')
		-- hs.keycodes.currentSourceID("com.apple.keylayout.US")
	end
end)

@knu
Copy link
Contributor

knu commented May 17, 2017

According to the author of Karabiner, OS X has a bug and there's a workaround. I'm not sure if it's fixed in Sierra, though. See here.

Out of curiosity, does hs.keycodes.currentSourceID(...) return true when switching fails?

@dcrozz
Copy link
Author

dcrozz commented May 17, 2017

@knu though it returns true, the input method still doesn't work...

@oleksandr-yefremov
Copy link

But sometime only the icon in input method menu changed (shows the Chinese input is selected) while only English can be input.

For me using currentSourceID or setLayout results in opposite behaviour: input source is changed, but icon is not updated in 90% of cases. But I can live with that, because I am using hotkeys for setting specific language (right_shift+1 for US, right_shift+2 for Ukrainian etc.) and hence I don't look at icon at all :) Gonna try applying mentioned fix on Sierra.

P.S. With Sierra breaking original Karabiner Hammerspoon is my saver!! Thanks, guys!

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

No branches or pull requests

4 participants