Compartir a través de


HardwareKeys Enumeration

[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]

Specifies the hardware buttons on a Pocket PC that can be accessed by the HardwareButton class.

Namespace:  Microsoft.WindowsCE.Forms
Assembly:  Microsoft.WindowsCE.Forms (in Microsoft.WindowsCE.Forms.dll)

Syntax

'Declaration
Public Enumeration HardwareKeys
'Usage
Dim instance As HardwareKeys
public enum HardwareKeys
public enum class HardwareKeys
type HardwareKeys

Members

Member name Description
Supported by the .NET Compact Framework None Specifies that no actual hardware buttons are associated with this HardwareButton instance.
Supported by the .NET Compact Framework ApplicationKey1 Specifies the hardware button that corresponds to application 1.
Supported by the .NET Compact Framework ApplicationKey2 Specifies the hardware button that corresponds to application 2.
Supported by the .NET Compact Framework ApplicationKey3 Specifies the hardware button that corresponds to application 3.
Supported by the .NET Compact Framework ApplicationKey4 Specifies the hardware button that corresponds to application 4.
Supported by the .NET Compact Framework ApplicationKey5 Specifies the hardware button that corresponds to application 5.
Supported by the .NET Compact Framework ApplicationKey6 Specifies the hardware button that corresponds to application 6.

Exceptions

Exception Condition
NotSupportedException

Remarks

The form or control associated with a member of this enumeration can receive the KeyDown and KeyUp events when the corresponding hardware button is pressed.

Note

The hardware buttons correspond to the application keys on a Pocket PC. The application keys are not included in the core key set, so their hardware key mapping may vary from one keyboard layout to the next. Only the default hardware key mapping on the device is supported.

This enumeration is not supported and throws a NotSupportedException on the Smartphone and other Windows CE devices that are not Pocket PCs.

Examples

The following code example uses the AssociatedControl and HardwareKey properties to display a form whenever the first and fourth buttons on Pocket PC are pressed. This code example is part of a larger example provided for the HardwareButton class.

Private Sub ConfigHWButton()
   'Set KeyPreview to true so that the form 
   'will receive key events before they 
   'are passed to the control that has focus. 

    Me.KeyPreview = True

      hwb1 = New HardwareButton()
      hwb4 = New HardwareButton()

   'Set the AssociatedControl property
   'to the current form and configure the
   'first and fourth buttons to activate the form.
   Try
      hwb1.AssociatedControl = Me
      hwb4.AssociatedControl = Me
      hwb1.HardwareKey = HardwareKeys.ApplicationKey1
      hwb4.HardwareKey = HardwareKeys.ApplicationKey4
   Catch exc As Exception
      MessageBox.Show(exc.Message + " Check if the hardware button is physically available on this device.")
   End Try
 End Sub

Private Overloads Sub OnKeyUp(sender As Object, e As KeyEventArgs) Handles MyBase.KeyUp
    ' When a hardware button is pressed and released,
    ' this form receives the KeyUp event. The OnKeyUp
    ' method is used to determine which hardware
    ' button was pressed, because the event data
    ' specifies a member of the HardwareKeys enumeration.
    Select Case CType(e.KeyCode, HardwareKeys)
      Case HardwareKeys.ApplicationKey1
         statusBar1.Text = "Button 1 pressed."

      Case HardwareKeys.ApplicationKey4
         statusBar1.Text = "Button 4 pressed."

      Case Else
   End Select
End Sub
// Configure hardware buttons
// 1 and 4 to activate the current form.
private void HBConfig()
    {
        try 
        {
            hwb1 = new HardwareButton();
            hwb4 = new HardwareButton();
            hwb1.AssociatedControl = this;
            hwb4.AssociatedControl = this;
            hwb1.HardwareKey = HardwareKeys.ApplicationKey1;
            hwb4.HardwareKey = HardwareKeys.ApplicationKey4;
        }
        catch (Exception exc)
        {
            MessageBox.Show(exc.Message + " Check if the hardware button is physically available on this device.");
        }
}

// When a hardware button is pressed and released,
// this form receives the KeyUp event. The OnKeyUp
// method is used to determine which hardware
// button was pressed, because the event data
// specifies a member of the HardwareKeys enumeration.
private void OnKeyUp(object sender, KeyEventArgs e)
{
    switch ((HardwareKeys)e.KeyCode)
    {
        case HardwareKeys.ApplicationKey1:
            statusBar1.Text = "Button 1 pressed.";
            break;

        case HardwareKeys.ApplicationKey4:
            statusBar1.Text = "Button 4 pressed.";
            break;

        default:
            break;
    }
}

Platforms

Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Version Information

.NET Compact Framework

Supported in: 3.5, 2.0

See Also

Reference

Microsoft.WindowsCE.Forms Namespace

Other Resources

How to: Use the HardwareButton Component