Click here to Skip to main content
12,949,858 members (81,288 online)
Click here to Skip to main content
Add your own
alternative version


21 bookmarked
Posted 12 Feb 2006

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...


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.


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 :)

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).


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


About the Author

Mick Doherty
United Kingdom United Kingdom
No Biography provided

You may also be interested in...


Comments and Discussions

GeneralSuggestion Pin
Shaun Wilde12-Feb-06 9:30
memberShaun Wilde12-Feb-06 9:30 
GeneralRe: Suggestion Pin
Mick Doherty12-Feb-06 11:32
memberMick Doherty12-Feb-06 11:32 

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

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

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