Register HotKey

Joined
Dec 6, 2010
Messages
1
Reaction score
0
Hi,
I've seen a few postings concerning registering a hotkey in an application for a CE device. I think I've done everything correctly, but I can't seem to get this to work. My application hides at startup, with an icon in the system tray to access it. Only problem there is that another application is supposed to take full screen control of the CE device making my application unreachable. So, I figured I'd use a hotkey to show the form again. Based on code examples I've seen here and other places, I did this in my startup form:

Public Class Configuration
Inherits System.Windows.Forms.Form

Public Declare Function RegisterHotKey Lib "coredll.dll" (ByVal hWnd As IntPtr, ByVal id As Integer, ByVal fsModifiers As Integer, ByVal vk As Integer) As Boolean
Public Declare Function UnregisterHotKey Lib "coredll.dll" (ByVal hWnd As IntPtr, ByVal id As Integer) As Integer
Declare Function GetCapture Lib "coredll.dll" () As IntPtr

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Capture = True
Dim hWnd As IntPtr = GetCapture()
Me.Capture = False
Dim IntID As Integer = 2122
Dim fsModifiers As Integer = Keys.Control
Dim vk As Integer = Keys.Escape
Result = RegisterHotKey(hWnd, IntID, fsModifiers, vk)
If Result = False Then
MsgBox("You need another hotkey", vbOKOnly, _
"'Error")
End If
End Sub

That code actually returns a value of false, but I also initialized hWnd as Me.Handle. That returned a True but still didn't work in the big picture. Anyway, I also created another class in this form(and as a separate module which didn't work either) with this code

Public Class Message_Listener
Inherits MessageWindow

Public Const WM_SETHOTKEY = &H32
Public Const WM_SHOWWINDOW = &H18
Public Const HK_SHIFTA = &H141 'Shift + A
Public Const HK_SHIFTB = &H142 'Shift * B
Public Const HK_CONTROLA = &H241 'Control + A
Public Const HK_ALTZ = &H270
Public Const WM_HOTKEY As Integer = &H312
Public Enum HOTKEY_MODIFIERS
HOTKEY_SHIFT = 1
HOTKEY_CONTROL = 2
HOTKEY_ALT = 4
HOTKEY_EXT = 8
End Enum
Public Enum HOTKEY_RETURN_VALS
Invalid_KeyCode = (-1)
Invalid_hWnd = 0
Success = 1
Duplicate_Hotkey = 2
End Enum
Private msgform As Configuration


Public Sub New(ByVal msgform As Configuration)
Me.msgform = msgform
End Sub


Protected Overrides Sub WndProc(ByRef msg As Microsoft.WindowsCE.Forms.Message)

Select Case msg.Msg
Case WM_HOTKEY
PLCMessageDisplay.Configuration.Show()
End Select
MyBase.WndProc(msg)
End Sub


End Class

That code never executes, which means the message never goes out. I'm guessing that there is a problem in the RegisterHotKey function where hWnd is wrong OR in this class where this form doesn't receive the WM_HOTKEY message for some reason. Any help would be greatly appreciated as I am at my wits end with this stupid thing. I've been searching for the answer for about a week.

Thanks!
Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top