C
Caroline
With previous versions of Windows Pocket PC I have been using the code
below, but now I switched to a iPAQ 114 using Windows Mobile 6 and it
doesn't work any more.
Anyone has an idea what could be wrong ??? Why isn't it possible to
override hardware keys in Windows Mobile 6 with "RegisterHotKey" ???
I have have the situation where when the hardware keys are pressed
they do what I want them to do BUT also still open the calendar,
contacts and inbox applications in addition - which is what I don't
want them to do. So I think there must be some problem with the
UnregisterFunc1, but I really don't know.
Please help,
thanks,
Caroline
Main class:
Private Sub KeyMessages_HardwareKeyPressed(ByVal sender As Object,
ByVal ke As HardwareKeyPressEventArgs) Handles
KeyMessages.HardwareKeyPressed
Select Case ke.KeyID
Case HardwareKey1
' do something
End Select
End Sub
Public Class HardwareKeyMessageWindow
Inherits MessageWindow
#Region " PInvoke Signatures For Hardware Key Capture "
<DllImport("coredll.dll")> _
Protected Shared Function RegisterHotKey(ByVal hWnd As IntPtr,
ByVal id As Integer, ByVal fsModifiers As Integer, ByVal vk As
Integer) As Integer
End Function
<DllImport("coredll.dll")> _
Protected Shared Function UnregisterFunc1(ByVal fsModifiers As
Integer, ByVal id As Integer) As Integer
End Function
Public Enum HardwareKeys
FirstHardwareKey = 193
HardwareKey1 = FirstHardwareKey
HardwareKey2 = 194
HardwareKey3 = 195
HardwareKey4 = 196
HardwareKey5 = 197
HardwareKey6 = 198
LastHardwareKey = HardwareKey6
'I have now found from the registry that these codes are
raised with the additional hardware keys
Windows = 91
Ok = 117
End Enum
Protected Const MOD_WIN As Integer = &H8
Protected Const WM_HOTKEY As Integer = &H312
#End Region
Public Sub New()
MyBase.New()
'-----------------------------------------------
'Disable Normal Hardware Key functions
'to allow us to process them.
'-----------------------------------------------
For i As Int32 = HardwareKeys.FirstHardwareKey To
HardwareKeys.LastHardwareKey
UnregisterFunc1(MOD_WIN, i)
RegisterHotKey(Me.Hwnd, i, MOD_WIN, i)
Next i
UnregisterFunc1(MOD_WIN, 91)
RegisterHotKey(Me.Hwnd, 91, MOD_WIN, 91)
UnregisterFunc1(MOD_WIN, 117)
RegisterHotKey(Me.Hwnd, 117, MOD_WIN, 117)
'-----------------------------------------------
End Sub
Public Event HardwareKeyPressed As HardwareKeyPressEventHandler
Protected Overrides Sub WndProc(ByRef m As
Microsoft.WindowsCE.Forms.Message)
If m.Msg <> WM_HOTKEY Then
MyBase.WndProc(m)
Else
Dim ke As New HardwareKeyPressEventArgs(m.WParam.ToInt32)
RaiseEvent HardwareKeyPressed(Me, ke)
End If
End Sub
End Class
below, but now I switched to a iPAQ 114 using Windows Mobile 6 and it
doesn't work any more.
Anyone has an idea what could be wrong ??? Why isn't it possible to
override hardware keys in Windows Mobile 6 with "RegisterHotKey" ???
I have have the situation where when the hardware keys are pressed
they do what I want them to do BUT also still open the calendar,
contacts and inbox applications in addition - which is what I don't
want them to do. So I think there must be some problem with the
UnregisterFunc1, but I really don't know.
Please help,
thanks,
Caroline
Main class:
Private Sub KeyMessages_HardwareKeyPressed(ByVal sender As Object,
ByVal ke As HardwareKeyPressEventArgs) Handles
KeyMessages.HardwareKeyPressed
Select Case ke.KeyID
Case HardwareKey1
' do something
End Select
End Sub
Public Class HardwareKeyMessageWindow
Inherits MessageWindow
#Region " PInvoke Signatures For Hardware Key Capture "
<DllImport("coredll.dll")> _
Protected Shared Function RegisterHotKey(ByVal hWnd As IntPtr,
ByVal id As Integer, ByVal fsModifiers As Integer, ByVal vk As
Integer) As Integer
End Function
<DllImport("coredll.dll")> _
Protected Shared Function UnregisterFunc1(ByVal fsModifiers As
Integer, ByVal id As Integer) As Integer
End Function
Public Enum HardwareKeys
FirstHardwareKey = 193
HardwareKey1 = FirstHardwareKey
HardwareKey2 = 194
HardwareKey3 = 195
HardwareKey4 = 196
HardwareKey5 = 197
HardwareKey6 = 198
LastHardwareKey = HardwareKey6
'I have now found from the registry that these codes are
raised with the additional hardware keys
Windows = 91
Ok = 117
End Enum
Protected Const MOD_WIN As Integer = &H8
Protected Const WM_HOTKEY As Integer = &H312
#End Region
Public Sub New()
MyBase.New()
'-----------------------------------------------
'Disable Normal Hardware Key functions
'to allow us to process them.
'-----------------------------------------------
For i As Int32 = HardwareKeys.FirstHardwareKey To
HardwareKeys.LastHardwareKey
UnregisterFunc1(MOD_WIN, i)
RegisterHotKey(Me.Hwnd, i, MOD_WIN, i)
Next i
UnregisterFunc1(MOD_WIN, 91)
RegisterHotKey(Me.Hwnd, 91, MOD_WIN, 91)
UnregisterFunc1(MOD_WIN, 117)
RegisterHotKey(Me.Hwnd, 117, MOD_WIN, 117)
'-----------------------------------------------
End Sub
Public Event HardwareKeyPressed As HardwareKeyPressEventHandler
Protected Overrides Sub WndProc(ByRef m As
Microsoft.WindowsCE.Forms.Message)
If m.Msg <> WM_HOTKEY Then
MyBase.WndProc(m)
Else
Dim ke As New HardwareKeyPressEventArgs(m.WParam.ToInt32)
RaiseEvent HardwareKeyPressed(Me, ke)
End If
End Sub
End Class