自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

C#打開軟鍵盤的方法

開發(fā) 后端
這里介紹C#打開軟鍵盤的方法,程序是在VS2005里面,注意一下??丶枰约禾砑恿?。一個ComboBox,一個Textbox,一個Button,直接拖進去沒有更改name。

以前曾經(jīng)見別人CSDN上面問過如何用C#打開軟鍵盤,我也關注過,可沒有結(jié)果。在網(wǎng)上搜了一下也沒有能找出滿意的答案。今天就拿這個開開刀吧,反正大項目也沒有,只是一個小功能。結(jié)果沒曾想,弄出來了。也有好久沒有更新我的這一畝三分田了,就放上來了。

獻給那些為中國共享軟件和提高中國程序水平作努力的人們。

注:程序是在VS2005里面,注意一下。控件需要自己添加了。一個ComboBox,一個Textbox,一個Button,直接拖進去沒有更改name

用C#打開軟鍵盤程序開始

 

  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.ComponentModel;  
  4. using System.Data;  
  5. using System.Drawing;  
  6. using System.Text;  
  7. using System.Windows.Forms;  
  8. using System.Runtime.InteropServices;  
  9.  
  10. namespace InputLanguageSwitch  
  11. {  
  12. /// <summary> 
  13. /// 獲取系統(tǒng)所有的輸入法,并可以程序改變當前輸入法;打開關閉軟鍵盤。  
  14. /// 程序:房客  
  15. /// QQ:83849123  
  16. /// Blog:http://www.cnblogs.com/sxlfybb  
  17. /// </summary> 
  18. public partial class Form1 : Form  
  19. {  
  20. public Form1()  
  21. {  
  22. InitializeComponent();  
  23. this.InputLanguageChanged += new InputLanguageChangedEventHandler
    (Form1_InputLanguageChanged);  
  24. }  
  25.  
  26. void Form1_InputLanguageChanged(object sender, InputLanguageChangedEventArgs e)  
  27. {  
  28. //throw new Exception("The method or operation is not implemented.");  
  29. for( int i=0;i<comboBox1.Items.Count;i++)  
  30. {  
  31. if (InputLanguage.CurrentInputLanguage.LayoutName == comboBox1.Items[i].ToString())  
  32. {  
  33. comboBox1.SelectedIndex = i;  
  34. }  
  35.  
  36. }  
  37. }  
  38.  
  39. private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)  
  40. {  
  41. string strTemp = comboBox1.Items[comboBox1.SelectedIndex].ToString();  
  42. InputLanguageCollection collects = InputLanguage.InstalledInputLanguages;  
  43. for (int i = 0; i < collects.Count; i++)  
  44. {  
  45. if (collects[i].LayoutName == strTemp)  
  46. InputLanguage.CurrentInputLanguage = collects[i];  
  47. }  
  48.  
  49. }  
  50.  
  51. private void Form1_Load(object sender, EventArgs e)  
  52. {  
  53. InputLanguageCollection collects = InputLanguage.InstalledInputLanguages;  
  54. for (int i = 0; i < collects.Count; i++)  
  55. {  
  56. comboBox1.Items.Add(collects[i].LayoutName);  
  57. }  
  58. comboBox1.SelectedIndex = collects.IndexOf(InputLanguage.CurrentInputLanguage);  
  59. }  
  60.  
  61. private void button1_Click(object sender, EventArgs e)  
  62. {  
  63. this.textBox1.Focus();  
  64. IntPtr hwndInput = ImmGetContext(this.Handle);  
  65. IntPtr dw1 = IntPtr.Zero;  
  66. IntPtr dw2 = IntPtr.Zero;  
  67. bool isSuccess = ImmGetConversionStatus(hwndInput, ref dw1, ref dw2);  
  68. if (isSuccess)  
  69. {  
  70. int intTemp = dw1.ToInt32() & IME_CMODE_SOFTKBD;  
  71. if (intTemp > 0)  
  72. dw1 = (IntPtr)(dw1.ToInt32() ^ IME_CMODE_SOFTKBD);  
  73. else  
  74. dw1 = (IntPtr)(dw1.ToInt32() IME_CMODE_SOFTKBD);  
  75. }  
  76. isSuccess = ImmSetConversionStatus(hwndInput, dw1, dw2);  
  77. ImmReleaseContext(this.Handle, hwndInput);  
  78. }  
  79.  
  80. public const int IME_CMODE_SOFTKBD = 0x80;  
  81.  
  82. [DllImport("imm32.dll", EntryPoint = "ImmGetContext")]  
  83. public static extern IntPtr ImmGetContext(  
  84. IntPtr hwnd  
  85. );  
  86. [DllImport("imm32.dll", EntryPoint = "ImmGetConversionStatus")]  
  87. public static extern bool ImmGetConversionStatus(  
  88. IntPtr himc,  
  89. ref IntPtr lpdw,  
  90. ref IntPtr lpdw2  
  91. );  
  92. [DllImport("imm32.dll", EntryPoint = "ImmSetConversionStatus")]  
  93. public static extern bool ImmSetConversionStatus(  
  94. IntPtr himc,  
  95. IntPtr dw1,  
  96. IntPtr dw2  
  97. );  
  98.  
  99. [DllImport("imm32.dll", EntryPoint = "ImmReleaseContext")]  
  100. public static extern int ImmReleaseContext(  
  101. IntPtr hwnd,  
  102. IntPtr himc  
  103. );  
  104.  
  105. }  


用C#打開軟鍵盤代碼結(jié)束。

另外,也可以直接執(zhí)行OSK而直接打開虛擬鍵盤,不過這個和軟鍵盤是不一樣的。
現(xiàn)在反釣魚的軟件越來越多了,祝大家共同進步。

【編輯推薦】

  1. 如何用C#和ADO.NET訪問
  2. 淺析C# Switch語句
  3. C#驗證輸入方法詳解
  4. 簡單介紹C# 匿名方法
  5. C# FileSystemWatcher對象
責任編輯:佚名 來源: IT168
相關推薦

2021-08-07 15:31:45

Windows 10Windows微軟

2024-03-06 09:16:57

PAD設備kikaInput鴻蒙

2024-05-06 08:28:09

Android窗口鍵盤

2017-12-05 13:12:35

Android軟鍵盤參數(shù)

2017-12-05 15:26:19

2020-03-24 09:34:00

移動端H5軟鍵盤

2017-07-03 17:20:55

Android軟鍵盤控制開發(fā)問題

2021-07-13 09:49:08

鴻蒙HarmonyOS應用

2019-04-25 10:20:22

H5軟鍵盤前端

2013-06-27 17:26:01

AndroidEditText

2013-04-01 17:05:28

2009-09-01 14:18:09

C#打開Excel文檔

2009-08-17 17:40:53

C# GetAllCu

2009-08-26 09:50:08

C# GreetPeo

2009-08-26 17:16:22

C# CheckSta

2009-08-19 15:54:33

處理C#消息

2009-08-03 12:57:27

C#調(diào)用DLL

2009-08-10 17:00:14

C#分部方法

2009-09-01 13:13:28

C#打開Word文檔

2009-09-07 15:49:55

C#屬性化的方法
點贊
收藏

51CTO技術(shù)棧公眾號