How to: Detect Navigation Keys
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer

How to: Detect Navigation Keys

You can determine when a user presses any 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.

Example

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;
        }
}

Compiling the Code

This example requires references to the following namespaces:

See Also

Show:
© 2016 Microsoft