C#和箭头键 [英] C# and Arrow Keys
问题描述
我是新的C#和我做了一些工作在现有的应用程序。我有一个具有成分在里面,我希望能够使用箭头键来定位的DirectX视口。
I am new to C# and am doing some work in an existing application. I have a DirectX viewport that has components in it that I want to be able to position using arrow keys.
目前,我重写ProcessCmdKey和醒目的箭头输入和发送的OnKeyPress事件。这工作,但我希望能够用改性剂( <大骨节病> ALT 骨节病> + <大骨节病> CTRL 骨节病> + <大骨节病> SHIFT 骨节病> )。当我捧着改性剂和按箭头没有事件被触发,我听着。
Currently I am overriding ProcessCmdKey and catching arrow input and send an OnKeyPress event. This works, but I want to be able to use modifiers(ALT+CTRL+SHIFT). As soon as I am holding a modifier and press an arrow no events are triggered that I am listening to.
有没有人有我应该去的地方的任何意见或建议此?
Does anyone have any ideas or suggestions on where I should go with this?
推荐答案
在您的覆盖ProcessCmdKey你是如何确定哪些键被按下?
Within your overridden ProcessCmdKey how are you determining which key has been pressed?
价值KEYDATA(第二个参数)将改变依赖按下键和任何修饰键,因此,例如,按下左箭头将返回码37,左移位将返回65573,CTRL-左131109和ALT左262181。
The value of keyData (the second parameter) will change dependant on the key pressed and any modifier keys, so, for example, pressing the left arrow will return code 37, shift-left will return 65573, ctrl-left 131109 and alt-left 262181.
您可以提取修饰符和AND运算适当枚举值按该键:
You can extract the modifiers and the key pressed by ANDing with appropriate enum values:
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
bool shiftPressed = (keyData & Keys.Shift) != 0;
Keys unmodifiedKey = (keyData & Keys.KeyCode);
// rest of code goes here
}
这篇关于C#和箭头键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!