How to: Detect Navigation Keys
This documentation is archived and is not being maintained.

How to: Detect Navigation Keys

The example in this topic shows how you can determine when a user presses any one of the four directions on a Pocket PC navigation pad or its Return button. You can extend this example to detect keys on a Pocket PC keyboard accessory.

The following example shows how to get the value of a key by overriding the OnKeyDown method and evaluating the KeyData property.

protected override void OnKeyDown(KeyEventArgs keyg)
{
        switch(keyg.KeyData)
        {
            case Keys.Left:
                label1.Text = "Left";
                break;
            case Keys.Right:
                label1.Text = "Right";
                break;
            case Keys.Down:
                label1.Text = "Down";
                break;
            case Keys.Up:
                label1.Text = "Up";
                break;
            case Keys.Return:
                label1.Text = "Return";
                break;
            default:
                break;
        }
}

This example requires references to the following namespaces:

Show:
© 2016 Microsoft