Accurately switch input methods in applications

Source: Internet
Author: User

If you need to enter a lot of content in your program, such as various types of documents, it will be a cool feature to automatically switch the Input Method to the appropriate State when entering each input box, compared with the dazzling interface, the input staff who typed hand cramps will be more interested in this. Switching the Input Method in winform is very simple:

 

Foreach (InputLanguage iL in InputLanguage. installedinputages)
{
If (iL. LayoutName = "smart ABC ")
{
InputLanguage. CurrentInputLanguage = iL;
Break;
}
}

 

This makes it easy to switch the input method to smart ABC.

However, this effect is not perfect. This method cannot specify the IME status, that is, the IME transition status. This concept exists only in windows in the Far East region, because for English-speaking countries, there is no input method, but in French, only a simple modification of key ing relationships is required for the language of Pinyin in the Russian and other Latins. Only the Chinese-affected East Asian regions have the concept of input methods, such as Japanese and Korean, for easy input, there are many statuses in these IME, such as Microsoft Japanese input method:

Japanese input includes the full-width and half-width Katakana and other input statuses, including:

Normal, name, dialog, and do not convert four Kana to the conversion mode when using Chinese Characters

 

 

The Chinese input method is relatively simple, and there is no conversion of Chinese characters, but there is also the exchange of Chinese and English (the cool Japanese prefer to replace English with Katakana, so there is no alternate input) however, there is a conversion between the Chinese and English input modes, a replacement of Chinese and English Punctuation Marks, and a full-width half-width conversion:

If the old smart ABC is used, there are still switching between doubles and the standard mode.

For the input modes in these various input methods, if you want to select the correct input mode, and you also need to determine the only mode to locate the input, then the InputLanguage class function will be stretched.

In windows text service IMM, IME provides the ConvertionStatus interface to determine the operating mode of the input method. In Win32API

ImmGetConversionStatus and ImmSetConversionStatus

These two functions have three parameters: one is the IME handle of the input method, the other is the mode, the other is the sentence, and the most important is the mode and sentence parameters, they are the data that determines the input method status. After testing, we found that the values of each input method are different. Therefore, it is too complicated to check the meanings of the enumerated values corresponding to the two int variables in MSDN, however, we only need to precisely switch to a certain mode, and only need to record the values of mode and sentence in these modes.

The following table lists the ing between the state and mode of the Chinese input method.

Doubles (including single-and double-doubles, such as Microsoft input)

Input Method status mode value Chinese Input-halfwidth-Chinese character-2147482623 Chinese Input-fullwidth-Chinese character-2147482615 Chinese Input-halfwidth-English character-2147483647 Chinese Input-fullwidth-English character-2147483839 english input-halfwidth-Chinese characters-2147482624 English input-fullwidth-Chinese characters-2147482616 English input-halfwidth-English symbols-2147483648 English input-fullwidth-English symbols-2147483640

 

Standard mode (full mode, such as the standard mode of smart ABC)

Input Method status mode value Chinese Input-halfwidth-Chinese Character 1025 Chinese Input-fullwidth-Chinese Character 1033 Chinese Input-halfwidth-English character 1 Chinese Input-fullwidth-English character 9 English input-halfwidth -Chinese characters 1024 English input-fullwidth-Chinese characters 1032 English input-halfwidth-English characters 0 English input-fullwidth-English symbols 8

 

Different Input Methods support different modes. For example, sogou supports standard modes, but because of its own functions

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.