上,下,左,右箭头键不会触发KeyDown事件 [英] Up, Down, Left and Right arrow keys do not trigger KeyDown event
问题描述
我建立,所有的按键输入必须由Windows本身进行处理的应用程序。
我设置的制表位为false每个控制女巫可以抢的焦点,除了面板(但我不知道有没有效果)。
我SET键preVIEW为真,我处理这种形式的KeyDown事件。
我的问题是,有时箭头键都没有反应了:
-
在我pressed只有方向键KeyDown事件不被解雇。
-
如果我preSS与对照修改方向键KeyDown事件被激发。
你有一个想法,为什么我的箭头键突然停止射击的事件?
保护覆盖布尔IsInputKey(钥匙KEYDATA)
{
开关(KEYDATA)
{
案例Keys.Right:
案例Keys.Left:
案例Keys.Up:
案例Keys.Down:
返回true;
案例Keys.Shift | Keys.Right:
案例Keys.Shift | Keys.Left:
案例Keys.Shift | Keys.Up:
案例Keys.Shift | Keys.Down:
返回true;
}
返回base.IsInputKey(KEYDATA);
}
保护覆盖无效的onkeydown(KeyEventArgs E)
{
base.OnKeyDown(E);
开关(e.Key code)
{
案例Keys.Left:
案例Keys.Right:
案例Keys.Up:
案例Keys.Down:
如果(e.Shift)
{ }
其他
{
}
打破;
}
}
I am building an application where all the key input must be handled by the windows itself.
I set tabstop to false for each control witch could grab the focus except a panel (but I don't know if it has effect).
I set KeyPreview to true and I am handling the KeyDown event on this form.
My problem is that sometimes the arrow key aren't responsive anymore:
The keydown event is not fired when I pressed only an arrow key.
The keydown event is fired if I press an arrow key with the control modifier.
Have you an idea why my arrow key suddenly stop firing event?
protected override bool IsInputKey(Keys keyData)
{
switch (keyData)
{
case Keys.Right:
case Keys.Left:
case Keys.Up:
case Keys.Down:
return true;
case Keys.Shift | Keys.Right:
case Keys.Shift | Keys.Left:
case Keys.Shift | Keys.Up:
case Keys.Shift | Keys.Down:
return true;
}
return base.IsInputKey(keyData);
}
protected override void OnKeyDown(KeyEventArgs e)
{
base.OnKeyDown(e);
switch (e.KeyCode)
{
case Keys.Left:
case Keys.Right:
case Keys.Up:
case Keys.Down:
if (e.Shift)
{
}
else
{
}
break;
}
}
这篇关于上,下,左,右箭头键不会触发KeyDown事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!