Capturing cursor keys ??

  • Thread starter Thread starter Sagaert Johan
  • Start date Start date
S

Sagaert Johan

Hi

I have a usercontrol , the keypress and keyup/down events do not seem to
work on the cursor keys .
How can i capture the cursor keys when my control has the focus ?

Johan
 
Sagaert,

Some of the keys are considered sepcial and are processed by the control.
Arrow keys (I guess this is what are you reffering to as cursor keys) are
among them.

In order to stop the control to thread these keys specially and to fire the
ususal events for them you need to override IsInputKey method. Here is an
example how to "unlock" the events for arrow keys:

In the user control add the following method:
protected override bool IsInputKey(Keys keyData)
{
if (keyData == Keys.Left || keyData == Keys.Right || keyData == Keys.Up
|| keyData == Keys.Down)
{
return true;
}
return base.IsInputKey(keyData);
}

Now the control will fire KeyUp/Down for arrow keys.
 
Many Thanks

Stoitcho Goutsev (100) said:
Sagaert,

Some of the keys are considered sepcial and are processed by the control.
Arrow keys (I guess this is what are you reffering to as cursor keys) are
among them.

In order to stop the control to thread these keys specially and to fire the
ususal events for them you need to override IsInputKey method. Here is an
example how to "unlock" the events for arrow keys:

In the user control add the following method:
protected override bool IsInputKey(Keys keyData)
{
if (keyData == Keys.Left || keyData == Keys.Right || keyData == Keys.Up
|| keyData == Keys.Down)
{
return true;
}
return base.IsInputKey(keyData);
}

Now the control will fire KeyUp/Down for arrow keys.
 
Back
Top