首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

c# 怎么获取键盘输入值

2012-09-19 
c# 如何获取键盘输入值?我的思路是: 在应用程序中创建一个txt文本; 通过”按键“记录键盘按键的值;句柄是一

c# 如何获取键盘输入值?
 
  我的思路是: 在应用程序中创建一个txt文本; 通过”按键“记录键盘按键的值;
   
  句柄是一个什么概念?

[解决办法]

C# code
private void textBox1_KeyPress(object sender, KeyPressEventArgs e){    MessageBox.Show(((int)(e.KeyChar)).ToString());}
[解决办法]
IntPtr hwnd = FindWindow(null, "a.txt"); 
if (hwnd.ToInt32() != 0)
{
if (SetForegroundWindow(hwnd))
SendKeys.SendWait(Keys.A.ToString()); 
}
else { MessageBox.Show("记事本没有运行 "); } 
Process myProcess = System.Diagnostics.Process.Start(@"D:\WINDOWS\notepad.exe");
 myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
 myProcess.WaitForInputIdle(1000);
 if (myProcess.Responding)
 {
SendKeys.SendWait("文字!");
SendKeys.SendWait("{ENTER}");
SendKeys.SendWait("%EA");
SendKeys.SendWait("^C");
SendKeys.SendWait("^V");
SendKeys.SendWait("%FS");
SendKeys.SendWait(@"C:\Test.txt");
SendKeys.SendWait("%S");
 }
private void Form1_KeyUp ( object sender , KeyEventArgs e ) 

MessageBox.Show(e.KeyCode.ToString ( )) ; 

句柄是一个32位的整数,是Windows在内存中维护的一个对象(窗口等)内存物理地址列表的整数索引

热点排行