Click here to Skip to main content
Click here to Skip to main content

Controlling Hardware Buttons on Pocket PC

, 12 Feb 2006 CPOL
Rate this:
Please Sign up or sign in to vote.
Controlling hardware buttons, the easy way...

Introduction

Have you ever tried to control the hardware buttons on your PPC? Seen the Input example in the article on MSDN and still have no idea what's going on? Well then, here I come to the rescue.

Background

Quite why MS can not make their examples simple enough for anyone to use I have no idea. I Googled for a simple example, but even after looking at every single link, I found no such thing, and so decided that maybe I should write about it. I did see a few cryptic responses in the newsgroups which pointed in the right direction, but actual examples are so much easier to digest.

I was going to put this article up on my site, but decided that CodeProject gets so many more users that it would be more beneficial here. The code is so simple that I don't believe it is necessary for me to convert it to C#, but if I do, then I will probably find a home for it on my site.

Using the Code

Well, it couldn't be any easier to use. Firstly, you'll need to add a reference to Microsoft.WindowsCE.Forms. Next, create an instance of the class:

Private WithEvents KeyMessages As New HardwareKeyMessageWindow()

Then respond to the HardwareKeyPressed() messages:

Private Sub KeyMessages_HardwareKeyPressed(ByVal sender As Object, _
            ByVal ke As HardwareKeyPressEventArgs) _
            Handles KeyMessages.HardwareKeyPressed
      Select Case ke.KeyID
          Case HardwareKey1
              'Do something
          Case HardwareKey2
              'Do something else
          Case HardwareKey3
              'Do some other thing
          Case HardwareKey4
              'Do nothing
          Case HardwareKey5
              'Throw General error stating that this button should not be pressed under any circumstances ;)
      End Select
End Sub

Points of Interest

Just to make the sample complete, I built a simple Etch-A-Sketch application. It's just a pity that there's no method to detect shaking Smile | :)

This is written in VS2003, but I expect it should work in VS2002.

I have tested the app on a Pocket PC running Windows for PocketPC 2002 (free gift of Viewsonic V37 from those nice people at MS) and Windows for PocketPC 2003 (NavMan PIN 570).

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Mick Doherty

United Kingdom United Kingdom
No Biography provided

Comments and Discussions

 
GeneralSuggestion PinmemberShaun Wilde12-Feb-06 10:30 
GeneralRe: Suggestion PinmemberMick Doherty12-Feb-06 12:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150123.1 | Last Updated 12 Feb 2006
Article Copyright 2006 by Mick Doherty
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid