简体   繁体   中英

ITfTextInputProcessor::Deactivate gets called unexpectedly on regaining focus

I am implementing a text service on windows. Things work fine. However when I shift window focus to another application and shift focus back to the original application, the selected text services gets de-activated (I notice a call to ITfTextInputProcessor::Deactivate ). I think this call is unexpected. Post this call, The service has to be re-activated manually. I am surely doing something goofy. Just that I don't know what it is.

Offhand, I'd say that you are indeed doing something goofy. :) In particular, I'd pay careful attention to your ITfThreadMgrEventSink::OnSetFocus implementation (and, obviously, you need to implement ITfThreadMgrEventSink in your text service and connect it via AdviseSink if you haven't already.)

After more research, I've figured out what's happening:

When you set focus back to Word, TSF gets the current thread's active keyboard layout (actually a locale ID). It then compares that keyboard layout with the language ID of the currently active text service.

If they're different, TSF then activates the text service for the active keyboard layout, and deactivates any previously active text service.

I believe this behavior is different on Vista/Windows 7.

The fix would be to use LoadKeyboardLayout / ActivateKeyboardLayout to set the process keyboard layout in your ITfTextInputProcessor::Activate implementation. Apparently some apps also need you to call ITfInputProcessorProfiles::ChangeCurrentLanguage () as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM