Up, Down, Left and Right arrow keys do not trigger KeyDown event?

Derive from a control class and you can override the ProcessCmdKey method. Microsoft chose to omit these keys from KeyDown events because they affect multiple controls and move the focus, but this makes it very difficult to make an app react to these keys in any other way.

It seems that ProcessCmdKey is the only way to handle the keyboard accurately. Thanks! – tinmaru Oct 30 '09 at 14:04.

Unfortunately, it is quite difficult to accomplish this with the arrow keys, due to restrictions in KeyDown events. However, there are a few ways to get around this: As @Snarfblam stated, you can override the ProcessCmdKey method, which retains the ability to parse arrow key presses. As the accepted answer from this question states, XNA has a built-in method called Keyboard.GetState(), which allows you to use arrow key inputs.

However, WinForms doesn't have this, but it can be done through a P/Invoke, or by using a class that helps with it. I recommend trying to use that class. It's quite simple to do so: var left = KeyboardInfo.

GetKeyState(Keys. Left); var right = KeyboardInfo. GetKeyState(Keys.

Right); var up = KeyboardInfo. GetKeyState(Keys. Up); var down = KeyboardInfo.

GetKeyState(Keys. Down); if (left. IsPressed) { //do something... } //etc... If you use this in combination with the KeyDown event, I think you can reliably accomplish your goal.

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 Key. Down: if (e. Shift) { } else { } break; } }.

I was having the exact same problem. I considered the answer @Snarfblam provided; however, if you read the documentation on MSDN, the ProcessCMDKey method is meant to override key events for menu items in an application. I recently stumbled across this article from microsoft, which looks quite promising: msdn.microsoft.com/en-us/library/system.... to microsoft, the best thing to do is set IsInputKey=true; in the PreviewKeyDown event after detecting the arrow keys.

Doing so will fire the KeyDown event. This worked quite well for me and was less hack-ish than overriding the ProcessCMDKey.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions