Home > Back-end >  Master how to obtain the current input method, please?
Master how to obtain the current input method, please?

Time:10-13

Each master, xiaodi bucai, to ask again!
Recently a virtual keyboard, access to the current input method, and display on the Label. As the input switch, will change! Another is to by clicking a Button to begin with the direct input "http://www." the site, convenient! Please master guidance!

CodePudding user response:

Searched, turn around, to weigh on the http://hi.baidu.com/%D0%A1code/blog/item/6bcf98f819337ad4b58f312d.html
The following is a quote -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Void GetCurrentIME ()//get the current input method
{
Char pwszKLID [KL_NAMELENGTH];
ZeroMemory (pwszKLID KL_NAMELENGTH);
GetKeyboardLayoutName (pwszKLID);
Hkeys hkeys;
LPCTSTR lpSubKey="System \ \ CurrentControlSet \ \ Control \ \ the rid_device_info_keyboard Layouts \ ";//input information storage key;
Long ret=RegOpenKeyEx (KEY_READ HKEY_LOCAL_MACHINE, lpSubKey, 0, & amp; Hkeys);
If (ERROR_SUCCESS!=(ret) return;
CHAR achKey [MAX_PATH];
DWORD cbMaxSubKey=MAX_PATH;
DWORD I=0;
While (RegEnumKeyEx (hkeys, I achKey, & amp; CbMaxSubKey, NULL, NULL, NULL, NULL)==ERROR_SUCCESS)
{

If (STRCMP (pwszKLID, achKey)==0)
{
Char curStrKey [MAX_PATH];
ZeroMemory (curStrKey MAX_PATH);
Strcat (curStrKey, lpSubKey);
Strcat (curStrKey, \ \ "");
Strcat (curStrKey achKey);
Hkeys hImeKey;
Char KeyValue [MAX_PATH];
DWORD dwTpye=REG_SZ;
DWORD dwStrLen=MAX_PATH;
ZeroMemory (KeyValue MAX_PATH);
RegOpenKeyEx (HKEY_LOCAL_MACHINE, curStrKey, 0, KEY_WRITE | KEY_READ, & amp; HImeKey);
RegQueryValueEx (hImeKey, Layout "Text", 0, & amp; DwTpye (LPBYTE) KeyValue, & amp; DwStrLen);
MessageBox (NULL, KeyValue, "", 0).
}
ZeroMemory (achKey MAX_PATH);
CbMaxSubKey=MAX_PATH;
i++;
}
RegCloseKey (hkeys);
}
//VS2008 + xp Dll Hook test success

Talk to first system input information location.

Open the registry to HKEY_LOCAL_MACHINE \ \ System \ \ CurrentControlSet \ \ Control \ \ the rid_device_info_keyboard Layouts \ \

There are a lot of folders, each named after a 8 words long string,

Click on any of them, you can see, there are two primary key value is of type REG_SZ,

A Layout File, record the input method used DLL,

A Layout is Text, record the input method of Chinese name.

In fact, the eight word long string is the input the ID of the



Know these, here we have to deal with if the current input method using.

First take a look at a WindAPI function:
BOOL GetKeyboardLayoutName (
LPTSTR pwszKLID//input locale identifier name
);

This function can easily get the current system are using the ID of the input method,

The problem is very obvious, we have to get is the ID of the input method name.

In this way, talk about the above registry will come in handy,

Because the HKEY_LOCAL_MACHINE \ \ System \ \ CurrentControlSet \ \ all under Control \ \ the rid_device_info_keyboard Layouts \ \

Some folders are named after the name of the input method ID,

As long as we get the input the ID of the location to the folder,

From one of the key: Layout Text get the Chinese name of the input method

CodePudding user response:

The
code:
AnsiString GetCurrentIME2 ()//get the current input method
{
Char pwszKLID [KL_NAMELENGTH];
AnsiString STR.
ZeroMemory (pwszKLID KL_NAMELENGTH);
GetKeyboardLayoutName (pwszKLID);
Hkeys hkeys;
LPCTSTR lpSubKey="System \ \ CurrentControlSet \ \ Control \ \ the rid_device_info_keyboard Layouts \ ";//input information storage key;
Long ret=RegOpenKeyEx (KEY_READ HKEY_LOCAL_MACHINE, lpSubKey, 0, & amp; Hkeys);
If (ERROR_SUCCESS!=(ret) return "";
CHAR achKey [MAX_PATH];
DWORD cbMaxSubKey=MAX_PATH;
DWORD I=0;
While (RegEnumKeyEx (hkeys, I achKey, & amp; CbMaxSubKey, NULL, NULL, NULL, NULL)==ERROR_SUCCESS)
{

If (STRCMP (pwszKLID, achKey)==0)
{
Char curStrKey [MAX_PATH];
ZeroMemory (curStrKey MAX_PATH);
Strcat (curStrKey, lpSubKey);
Strcat (curStrKey, \ \ "");
Strcat (curStrKey achKey);
Hkeys hImeKey;
Char KeyValue [MAX_PATH];
DWORD dwTpye=REG_SZ;
DWORD dwStrLen=MAX_PATH;
ZeroMemory (KeyValue MAX_PATH);
RegOpenKeyEx (HKEY_LOCAL_MACHINE, curStrKey, 0, KEY_WRITE | KEY_READ, & amp; HImeKey);
RegQueryValueEx (hImeKey, Layout "Text", 0, & amp; DwTpye (LPBYTE) KeyValue, & amp; DwStrLen);
//MessageBox (NULL, KeyValue, "", 0).
STR=KeyValue;
}
ZeroMemory (achKey MAX_PATH);
CbMaxSubKey=MAX_PATH;
i++;
}
RegCloseKey (hkeys);
return str;
}

CodePudding user response:

The
code:
AnsiString GetCurrentIME2 ()//get the current input method
{
Char pwszKLID [KL_NAMELENGTH];
AnsiString STR.
ZeroMemory (pwszKLID KL_NAMELENGTH);
GetKeyboardLayoutName (pwszKLID);
Hkeys hkeys;
LPCTSTR lpSubKey="System \ \ CurrentControlSet \ \ Control \ \ the rid_device_info_keyboard Layouts \ ";//input information storage key;
Long ret=RegOpenKeyEx (KEY_READ HKEY_LOCAL_MACHINE, lpSubKey, 0, & amp; Hkeys);
If (ERROR_SUCCESS!=(ret) return "";
CHAR achKey [MAX_PATH];
DWORD cbMaxSubKey=MAX_PATH;
DWORD I=0;
While (RegEnumKeyEx (hkeys, I achKey, & amp; CbMaxSubKey, NULL, NULL, NULL, NULL)==ERROR_SUCCESS)
{

If (STRCMP (pwszKLID, achKey)==0)
{
Char curStrKey [MAX_PATH];
ZeroMemory (curStrKey MAX_PATH);
Strcat (curStrKey, lpSubKey);
Strcat (curStrKey, \ \ "");
Strcat (curStrKey achKey);
Hkeys hImeKey;
Char KeyValue [MAX_PATH];
DWORD dwTpye=REG_SZ;
DWORD dwStrLen=MAX_PATH;
ZeroMemory (KeyValue MAX_PATH);
RegOpenKeyEx (HKEY_LOCAL_MACHINE, curStrKey, 0, KEY_WRITE | KEY_READ, & amp; nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related