This documentation is archived and is not being maintained.

How to: Override Smartphone Soft Keys

Normally, Smartphone soft keys operate menus; however, you can provide custom soft key functionality by removing the MainMenu component from your form. When there is no menu in a Smartphone application, Soft Key 1 and Soft Key 2 presses raise the KeyDown event followed by a KeyUp event when the keys are released.

The KeyCode field recognizes F1 as Soft Key 1, and F2 as Soft Key 2.

The following code example shows how to provide event handling code for soft key presses.

Visual C# users need to define an event hander for the KeyPress event in the form's constructor.

// Connect an event handler to the KeyPress event 
this.KeyPress += new KeyPressEventHandler(OnKeyPress);
private void OnKeyPress(object sender, KeyPressEventArgs ke)
  // Determine if ESC key value is raised. 
  if (ke.KeyChar == (Char)Keys.Escape)
      // Handle the event to provide functionality.
      ke.Handled = true;

      // Add your event handling code here.
     MessageBox.Show("Custom back key functionality.");

This example requires references to the following namespaces: