QA: How can I set the qwerty keyboard as the current input method?

Yaroslav Goncharov (yaroslav@softspb.com), November 09, 2001.

Question

My application needs to set qwerty keyboard as current input method. How can I do it?

Answer

You can use SipSetCurrentIM(CLSID *pClsid)method to set current input method. Now we need to find class id for qwerty keyboard. The following source code sets qwerty keyboard as current input method.

CLSID clsidQwertyIM = __uuidof(CMSQwertyIm); ::SipSetCurrentIM(&clsidQwertyIM);

However, this solution is not perfect. Lets imagine the situation when there is no qwerty keyboard in the system or modern keyboard replaces default one. MSDN says If the SIP is unable to load the IM, the default IM is loaded in its place. But in fact, system can have unpredictable behavior in this situation. For instance, Cassiopeia E-125 will deselect current IM and user will not see SIP panel in response on SIP button mouse click. The following method solves this problem.

#include <sip.h> // This method sets qwerty keyboard as current IM // RET: TRUE indicates success. FALSE indicates failure. BOOL SetQwertyAsCurrentIM() { CLSID clsidQwertyIM = __uuidof(CMSQwertyIm); CLSID clsidOldIM, clsidCurIM; ::SipGetCurrentIM(&clsidOldIM); ::SipSetCurrentIM(&clsidQwertyIM); ::SipGetCurrentIM(&clsidCurIM); // check if qwerty was set if (clsidQwertyIM != clsidCurIM) { // set the old IM to avoid unpredictable behavior ::SipSetCurrentIM(&clsidOldIM); return FALSE; } return TRUE; }

Related resources: