HTML5技术

C# 输入法 - YSWALLE(2)

字号+ 作者:H5之家 来源:H5之家 2017-03-10 18:00 我要评论( )

Stop() 2 { 3 bool retKeyboard = true ; (hKeyboardHook != 0 ) 7 { 8 retKeyboard = UnhookWindowsHookEx(hKeyboardHook); 9 hKeyboardHook = 0 ; 10 } (! (retKeyboard)) Exception( ); 14 } 4.注册事件 WordBoa

Stop() 2 { 3 bool retKeyboard = true; (hKeyboardHook != 0) 7 { 8 retKeyboard = UnhookWindowsHookEx(hKeyboardHook); 9 hKeyboardHook = 0; 10 } (!(retKeyboard)) Exception(); 14 }

 

4.注册事件

WordBoard_Load(object sender, EventArgs e) 2 { 3 Program.keyBordHook.KeyUpEvent += KeyBordHook_KeyUpEvent; 4 Program.keyBordHook.OnSpaced += KeyBordHook_OnSpaced; 5 Program.keyBordHook.OnBacked += KeyBordHook_OnBacked; 6 }

 

5.根据输入内容显示并进行转换

ShowCharatar() 2 { 3 this.listView1.BeginInvoke(new Action(() => 4 { 5 label1.Text = keys; { 9 this.listView1.Items.Clear(); 10 var arr = CacheHelper.Get(keys); 11 if (arr != null) 12 for (int i = 0; i < (arr.Length > 10 ? 9 : arr.Length); i++) 13 { + arr[i]); 15 } 16 } { 19 label1.Text = keys = ""; 20 } 21 })); 22 }

 

6.显示输入

KeyBordHook_KeyUpEvent(object sender, KeyEventArgs e) 2 { 3 keys += e.KeyCode.ToString().ToLower(); 4 this.ShowCharatar(); 5 }

 

7.空格上屏

KeyBordHook_OnSpaced(int choose) 2 { { 5 if (CacheHelper.ContainsKey(keys)) 6 { 7 if (choose > 0) 8 { 9 choose = choose - 1; 10 } 11 12 Program.keyBordHook.Send(CacheHelper.Get(keys)[choose]); 13 label1.Text = ""; 14 this.listView1.Clear(); 15 } 16 } { 19 20 } 21 keys = ""; 22 }

8.将数据发送到激活的输入框中

Send(string msg) 2 { 3 if (!string.IsNullOrEmpty(msg)) 4 { 5 Stop(); + msg); 7 Start(); 8 } 9 }

 

9.back键回退

KeyBordHook_OnBacked() 2 { 3 if (!string.IsNullOrEmpty(keys)) 4 { 5 keys = keys.Substring(0, keys.Length - 1); 6 } 7 this.ShowCharatar(); 8 }

 

当然这里还可以使其他键来完善更多的功能,例如拼音的分页处理等

 

 

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

相关文章
  • 【干货】JS版汉字与拼音互转终极方案,附简单的JS拼音输入法 - 我是小茗同学

    【干货】JS版汉字与拼音互转终极方案,附简单的JS拼音输入法 - 我是

    2016-10-19 18:00

网友点评
<