捕获所有键盘键包括 [英] capture all keyboard key including
本文介绍了捕获所有键盘键包括的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在c#.net
推荐答案
中捕获所有键盘键,包括键左键,键右键,键盘键事件一旦我发现有些情况我在哪里无法使用该方法捕获击键。这篇文章中描述的方法帮助我和mey在某些情况下有用:http://social.msdn.microsoft.com/Forums/vstudio/en-US/cf884a91-c135-447d-b16b- 214d2d9e9972 / capture-all-keyboard-input-what-what-control-has-focus [ ^ ]
Once I found there were some situations where I was not able to capture keystrokes with that method. The method described in this post helped me and mey be useful in some cases: http://social.msdn.microsoft.com/Forums/vstudio/en-US/cf884a91-c135-447d-b16b-214d2d9e9972/capture-all-keyboard-input-regardless-of-what-control-has-focus[^]
private void Form1_Load(object sender, EventArgs e)
{
this.KeyPreview = true;
this.PreviewKeyDown += new PreviewKeyDownEventHandler(Form1_PreviewKeyDown);
textBox1.PreviewKeyDown += new PreviewKeyDownEventHandler(Form1_PreviewKeyDown);
}
private void Form1_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
{
try
{
MessageBox.Show(e.KeyCode.ToString() + " key pressed on " + sender.ToString());
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
使用任何控件的keydown事件..
这里我用的是textbox' x KeyDown事件..
use keydown event of any control ..
here i am used textbox'x KeyDown event..
private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
MessageBox.Show(e.KeyData.ToString());
}
这篇关于捕获所有键盘键包括的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文