C # Use code to open the keyboard

Source: Internet
Author: User

I studied APIs some time ago, but I didn't play C # any more because of my work. I work overtime this evening, and wait for other departments to wait until a little more early in the morning. I just took the opportunity to play a game, just to learn about vs2005.
I used to see how to use csdn.ProgramWhen I opened the soft keyboard, I also paid attention to it, but there was no result. I searched the internet and couldn't find a satisfactory answer. Today, let's get started with this. There is no anti-zhengda project, just a small function. I did not think about the result. I haven't updated my three-point field for a long time.

To those who are making efforts to share software in China and improve the program level in China.

Note: The program is in vs2005. Pay attention to it. Control needs to be added by yourself. A ComboBox, A Textbox, and a button are dragged in directly without changing the name.

The following procedure starts
========================================

Using system;
Using system. Collections. Generic;
Using system. componentmodel;
Using system. Data;
Using system. drawing;
Using system. text;
Using system. Windows. forms;
Using system. runtime. interopservices;

Namespace input1_ageswitch
{
/// <Summary>
/// Obtain all input methods of the system and change the current input method by using the program. Enable and disable the soft keyboard.
/// Program: Tenant
/// QQ: 83849123
// Blog: http://www.cnblogs.com/sxlfybb
/// </Summary>
Public partial class form1: Form
{
Public form1 ()
{
Initializecomponent ();
This. inputlanguagechanged + = new inputlanguagechangedeventhandler (form=inputlanguagechanged );
}

Void form1_inputlanguagechanged (Object sender, inputlanguagechangedeventargs E)
{
// Throw new exception ("the method or operation is not implemented .");
For (INT I = 0; I <combobox1.items. Count; I ++)
{
If (inputlanguage. currentinputlanguage. layoutname = combobox1.items [I]. tostring ())
{
Combobox1.selectedindex = I;
}

}
}

Private void combobox#selectedindexchanged (Object sender, eventargs E)
{
String strtemp = combobox1.items [combobox1.selectedindex]. tostring ();
Inputlanguagecollection collects = inputlanguage. installedinputlanguages;
For (INT I = 0; I <collects. Count; I ++)
{
If (collects [I]. layoutname = strtemp)
Inputlanguage. currentinputlanguage = collects [I];
}

}

Private void form1_load (Object sender, eventargs E)
{
Inputlanguagecollection collects = inputlanguage. installedinputlanguages;
For (INT I = 0; I <collects. Count; I ++)
{
Combobox1.items. Add (collects [I]. layoutname );
}
Combobox1.selectedindex = collects. indexof (inputlanguage. currentinputlanguage );
}

Private void button#click (Object sender, eventargs E)
{
This. textbox1.focus ();
Intptr hwndinput = immgetcontext (this. Handle );
Intptr dw1 = intptr. zero;
Intptr dw2 = intptr. zero;
Bool issuccess = immgetconversionstatus (hwndinput, ref dw1, ref dw2 );
If (issuccess)
{
Int inttemp = dw1.toint32 () & ime_cmode_softkbd;
If (inttemp> 0)
Dw1 = (intptr) (dw1.toint32 () ^ ime_cmode_softkbd );
Else
Dw1 = (intptr) (dw1.toint32 () | ime_cmode_softkbd );
}
Issuccess = immsetconversionstatus (hwndinput, dw1, dw2 );
Immreleasecontext (this. Handle, hwndinput );
}

Public const int ime_cmode_softkbd = 0x80;

[Dllimport ("imm32.dll", entrypoint = "immgetcontext")]
Public static extern intptr immgetcontext (
Intptr hwnd
);
[Dllimport ("imm32.dll", entrypoint = "immgetconversionstatus")]
Public static extern bool immgetconversionstatus (
Intptr himc,
Ref intptr lpdw,
Ref intptr lpdw2
);
[Dllimport ("imm32.dll", entrypoint = "immsetconversionstatus")]
Public static extern bool immsetconversionstatus (
Intptr himc,
Intptr dw1,
Intptr dw2
);

[Dllimport ("imm32.dll", entrypoint = "immreleasecontext")]
Public static extern int immreleasecontext (
Intptr hwnd,
Intptr himc
);

}
}

====================================
CodeEnd.
In addition, you can directly execute osk and directly open the virtual keyboard, but this is different from the soft keyboard.
Now, more anti-phishing software is available, and I wish you all the same progress.

Thank you for your support. I sent it last night. Now several people have asked me about it. For your convenience, I have also sent the source program to the attachment, for your download reference.

Click to download

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.