AvocadoSoftware.com

Software For Hardcore Developers
Welcome to AvocadoSoftware.com Sign in | Join | Help
in Search

Derick Baileys old blog archives - go to derickbailey.com for new contents

Pocket PC : RegisterHotKey class wrapper.

Many thanks to the good folks over at OpenNetCF.org and the users who post into the forums. I've taken the basic code in This Thread and created a wrapper class for the Pocket PC RegisterHotKey / UnregisterHotKey API calls.

Essentially what I needed to do was create a hotkey button on a Pocket PC Windows form to allow a user to either click menu items with the stylus or to click the various keys on their keyboard and navigate around the app that way. I initially started going down the route trying to find an SDK method inside of the Symbol SDK for the specific device that we are devloping against. However, I was unable to find any kind of global KeyPress event and SetWindowsHookEx is not supported in the compact framework.

After much frustration and almost giving up on the idea, I finally ran into the post mentioned above and was able to convert the sample form provided into a class that wraps the registration / unregistration of hotkeys on the Pocket PC. The best part is, since this is using API calls from the Pocket PC itself, it's device independant. I don't have to worry about it working / not working in my emulator vs. the actual device.

 

I've Posted The Wrapper Class Here for anyone who needs to create any kind of keyboard hook on the compact framework.

 

Here's an example of how to use this class:

  Private WithEvents hk As New HotKeys

 

  Private Sub Form_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load

    hk.Register(Keys.X, HotKeys.KeyModifiers.Control)

    hk.Register(Keys.Y, HotKeys.KeyModifiers.Control)

  End Sub

 

  Private Sub Form_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing

    hk.UnRegister(Keys.X)

    hk.UnRegister(Keys.Y)

  End Sub

 

  Private Sub hk_KeyPress(ByVal key As Keys) Handles hk.KeyPressed

    MsgBox("You Pressed ctrl-" & key.ToString)

  End Sub

Published Thursday, February 17, 2005 2:54 PM by dredge
Filed Under: , ,
New Comments to this post are disabled

This Blog

Post Calendar

<February 2005>
SuMoTuWeThFrSa
303112345
6789101112
13141516171819
20212223242526
272812345
6789101112

Advertisement

News

this is my old blog archives - go to http://derickbailey.com for updates

Syndication

Advertisement

Powered by Community Server, by Telligent Systems