在定时器中检测多个按键如何? [英] Detect Multiple keypress in timer HOW ?
本文介绍了在定时器中检测多个按键如何?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
private void timer1_Tick(对象发件人,EventArgs e){
if (Form.ModifierKeys == System.Windows.Forms.Keys .Control&& Form.ModifierKeys == System.Windows.Forms.Keys.Enter)
my_translate(textbox1.text);
}
我试试但不工作怎么办?
我正在写一本字典软件;使用计时器我检查确定按下的键,所以我翻译单词。
// 代码正常工作
private void timer1_Tick( object sender,EventArgs e){
MouseButtons aa = MouseButtons;
if (aa == MouseButtons.Middle&& Form.ModifierKeys == Keys.Control)
my_translate(textbox1.text);
}
解决方案
您必须使用给定的EventArgument属性来确定按下了哪个Key。
喜欢这个
private void objectXY_KeyPress( object sender,System.Windows.Forms.KeyPressEventArgs e)
{
if (e.KeyChar ==( char )Keys.Enter&& Form.ModifierKeys == Forms.Keys。控制)
{}
}
或者这个(取决于你工作的.NET版本)
private void textBox1_KeyPress( object sender,System.Windows.Forms.KeyPressEventArgs e)
{
if (e.KeyCode == Keys.Enter&& ; e.Modifiers == Keys.Control)
{}
}
这个是处理多个修饰符。
< pre lang =c#> private void textBox1_KeyPress( object sender,System.Windows.Forms.KeyPressEventArgs e)
{
if (e.KeyCode == Keys.Enter& &安培; e.Modifiers ==(Keys.Control || Keys.Shift)
{}
}
我认为这会有所帮助为您的解决方案: http: //social.msdn.microsoft.com/Forums/vstudio/en-US/c7f4542f-c1c5-4cfa-ac04-521d4e7ef1a5/c-detect-multiple-keypress [ ^ ]
private void timer1_Tick(object sender, EventArgs e){
if (Form.ModifierKeys == System.Windows.Forms.Keys.Control && Form.ModifierKeys == System.Windows.Forms.Keys.Enter)
my_translate(textbox1.text);
}
I try it but dont work how can I do it?
I am writing a dictionary software; with timer I check determine pressed keys so I translate word.
//The code is working
private void timer1_Tick(object sender, EventArgs e){
MouseButtons aa = MouseButtons;
if (aa == MouseButtons.Middle && Form.ModifierKeys == Keys.Control)
my_translate(textbox1.text);
}
解决方案
You would have to use the given EventArgument Property to determine which Key was pressed.
like this
private void objectXY_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) { if(e.KeyChar == (char)Keys.Enter && Form.ModifierKeys == Forms.Keys.Control) { } }
or this (depends on which .NET Version you work)
private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) { if( e.KeyCode == Keys.Enter && e.Modifiers == Keys.Control) { } }
This one is to handle multiple modifiers.
private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) { if( e.KeyCode == Keys.Enter && e.Modifiers == (Keys.Control || Keys.Shift) { } }
I think this will be helpful for your solution : http://social.msdn.microsoft.com/Forums/vstudio/en-US/c7f4542f-c1c5-4cfa-ac04-521d4e7ef1a5/c-detect-multiple-keypress[^]
这篇关于在定时器中检测多个按键如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文