Windows Mobile "Soft Key" buttons

Perhaps this is obvious, but...

If you want to capture the Left/Right "Soft Key" buttons in a .NET application, add a handler to the KeyDown event of the Form, make sure there's no Menu, and look for F1/F2.

The gotcha that I ran into was looking for the KeyDown events on the (only) child control of the Form.

For example, for a fullscreen app:
this.KeyDown += new System.Windows.Forms.KeyEventHandler( this.MyForm_KeyDown );
this.Menu = null;
this.WindowState = FormWindowState.Maximized;

private void MyForm_KeyDown( object sender, KeyEventArgs e )
{
 switch( e.KeyCode )
 {
  case Keys.F1:
  {
   // Soft Key 1, when there's no Menu
   ...
   break;
  }
  case Keys.F2:
  {
   // Soft Key 2, when there's no Menu
   ...
   break;
  }
 }
}

Comments