前段时间研究过API
后来由于工作关系就没有再玩C#
而别说API了
今天晚上正好加班
等其他部门出活等到凌晨一点多了
还没有动静
就趁机耍一耍了
正好学习一下VS
以前曾经见别人CSDN上面问过如何用程序打开软键盘我也关注过可没有结果在网上搜了一下也没有能找出满意的答案今天就拿这个开开刀吧反正大项目也没有只是一个小功能结果没曾想弄出来了也有好久没有更新我的这一亩三分田了就放上来了
献给那些为中国共享软件和提高中国程序水平作努力的人们
注程序是在VS里面注意一下控件需要自己添加了一个ComboBox一个Textbox一个Button直接拖进去没有更改name
以下程序开始
==================================
using System;
using SystemCollectionsGeneric;
using SystemComponentModel;
using SystemData;
using SystemDrawing;
using SystemText;
using SystemWindowsForms;
using SystemRuntimeInteropServices;
namespace InputLanguageSwitch
{
/// <summary>
/// 获取系统所有的输入法并可以程序改变当前输入法打开关闭软键盘
/// 程序房客
/// QQ
/// Blog
/// </summary>
public partial class Form : Form
{
public Form()
{
InitializeComponent();
thisInputLanguageChanged += new InputLanguageChangedEventHandler(Form_InputLanguageChanged);
}
void Form_InputLanguageChanged(object sender InputLanguageChangedEventArgs e)
{
//throw new Exception(The method or operation is not implemented);
for( int i=;i<comboBoxItemsCount;i++)
{
if (InputLanguageCurrentInputLanguageLayoutName == comboBoxItems[i]ToString())
{
comboBoxSelectedIndex = i;
}
}
}
private void comboBox_SelectedIndexChanged(object sender EventArgs e)
{
string strTemp = comboBoxItems[comboBoxSelectedIndex]ToString();
InputLanguageCollection collects = InputLanguageInstalledInputLanguages;
for (int i = ; i < collectsCount; i++)
{
if (collects[i]LayoutName == strTemp)
InputLanguageCurrentInputLanguage = collects[i];
}
}
private void Form_Load(object sender EventArgs e)
{
InputLanguageCollection collects = InputLanguageInstalledInputLanguages;
for (int i = ; i < collectsCount; i++)
{
comboBoxItemsAdd(collects[i]LayoutName);
}
comboBoxSelectedIndex = collectsIndexOf(InputLanguageCurrentInputLanguage);
}
private void button_Click(object sender EventArgs e)
{
thistextBoxFocus();
IntPtr hwndInput = ImmGetContext(thisHandle);
IntPtr dw = IntPtrZero;
IntPtr dw = IntPtrZero;
bool isSuccess = ImmGetConversionStatus(hwndInput ref dw ref dw);
if (isSuccess)
{
int intTemp = dwToInt() & IME_CMODE_SOFTKBD;
if (intTemp > )
dw = (IntPtr)(dwToInt() ^ IME_CMODE_SOFTKBD);
else
dw = (IntPtr)(dwToInt() IME_CMODE_SOFTKBD);
}
isSuccess = ImmSetConversionStatus(hwndInput dw dw);
ImmReleaseContext(thisHandle hwndInput);
}
public const int IME_CMODE_SOFTKBD = x;
[DllImport(immdll EntryPoint = ImmGetContext)]
public static extern IntPtr ImmGetContext(
IntPtr hwnd
);
[DllImport(immdll EntryPoint = ImmGetConversionStatus)]
public static extern bool ImmGetConversionStatus(
IntPtr himc
ref IntPtr lpdw
ref IntPtr lpdw
);
[DllImport(immdll EntryPoint = ImmSetConversionStatus)]
public static extern bool ImmSetConversionStatus(
IntPtr himc
IntPtr dw
IntPtr dw
);
[DllImport(immdll EntryPoint = ImmReleaseContext)]
public static extern int ImmReleaseContext(
IntPtr hwnd
IntPtr himc
);
}
}
==============================
代码结束
另外也可以直接执行OSK而直接打开虚拟键盘不过这个和软键盘是不一样的
现在反钓鱼的软件越来越多了祝大家共同进步
谢谢大家的支持昨天晚上发的到现在已经有好几个人加我问我了为了方便大家我把源程序一并也发在附件里以供大家下载参考
点击下载