PDA

Click to See Complete Forum and Search --> : [RESOLVED] Assigning Hardware buttons


pmd13
Jun 4th, 2009, 09:28 PM
This is related my earlier post about disabling buttons. I have an HTC Touch. After my form loaded i was able to disable the camera button on the side. For some reason i can't disable the 2 app launch buttons and the rocker. I looked at the registry and only Button 1 is assigned (193 - camera). Are these special buttons that can't be disabled? Or is there a way to assign them to registry? Thanks!

The code below is what shows up when I click on the rocker and the app launch buttons from design in VS2008.


Private Sub msgapi_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
If (e.KeyCode = System.Windows.Forms.Keys.Up) Then
'Up
End If
If (e.KeyCode = System.Windows.Forms.Keys.Down) Then
'Down
End If
If (e.KeyCode = System.Windows.Forms.Keys.Left) Then
'Left
End If
If (e.KeyCode = System.Windows.Forms.Keys.Right) Then
'Right
End If
If (e.KeyCode = System.Windows.Forms.Keys.Enter) Then
'Enter
End If
End Sub

petevick
Jun 5th, 2009, 10:46 AM
try
e.handled = true
after the 'Up
that should ignore it

pmd13
Jun 6th, 2009, 04:06 AM
nope, sorry didn't work. I was looking around and I'm seeing people use the UnregisterHotkey and VK_T VOLUME UP then reregister and define what it does.
I think http://social.msdn.microsoft.com/Forums/en-US/vssmartdevicesnative/thread/981f2a71-3f5f-4c46-84c3-aa75ce614350/
might be what im looking for..just trying to figure it all out..

petevick
Jun 6th, 2009, 05:57 AM
You need to set keypreview to true on your form, and handle the events in the form keydown event

Private Sub Form1_KeyDown(sender As Object, e As KeyEventArgs)


'...
e.Handled = True

'...

End Sub

pmd13
Jun 6th, 2009, 03:54 PM
I made it true for each of the directions and Enter.
If I did the below correctly it didn't seem to have any affect on the rocker and app buttons. I was looking at the definitions and its for the arrow keys. Is the rocker considered an up or down arrow? If not i can't seem to find any ref for it in System.Windows.Forms.Keys

THanks for your help


Private Sub msgapi_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
If (e.KeyCode = System.Windows.Forms.Keys.Up) Then
'Up
e.Handled = True
End If
...
end sub

petevick
Jun 7th, 2009, 03:51 AM
hi,
Take a look at this video (http://msdn.microsoft.com/en-us/netframework/cc721665.aspx)from Jim Wilson and see if it helps

pmd13
Jun 7th, 2009, 06:39 PM
Hahaha i probably watched that video 50 times. It only worked for the camera button so I looked into the registry and sure enough it was the only one registered. I did figure out a work around.

First I made a quick form to display what the keycode is for any button i pressed.


Imports Microsoft.WindowsCE.Forms

Private Sub DetectionCode_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown, MyBase.KeyUp

StatusBar2.Text = e.KeyCode

end sub


I used the keycode and looked into the definition list for what they are. Surprisingly it was F3,F4,etc
For some reason even with the e.Handled = True pressing a button would still jump into the calendar and contacts. So i put in a .25 second timer that is triggered every time one of the assigned function keys are pressed to bring the form back on top. Technically i didn't re-assign the hardware keys but it does exactly what i want and thats to keep people in the program kiosk style. Thanks for your help. I really appreciate it.

Below detects both the hardware button keycode and if its assigned in the registry.



Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ConfigHWButton()
End Sub
Private Sub ConfigHWButton()
'Set KeyPreview to true so that the form
'will receive key events before they
'are passed to the control that has focus.

Me.KeyPreview = True

Dim hwb1 As New HardwareButton()
Dim hwb2 As New HardwareButton()
Dim hwb3 As New HardwareButton()
Dim hwb4 As New HardwareButton()
Dim hwb5 As New HardwareButton()
Dim hwb6 As New HardwareButton()

'Set the AssociatedControl property
'to the current form and configure the
'first and fourth buttons to activate the form.
Try
hwb1.AssociatedControl = Me
hwb2.AssociatedControl = Me
hwb3.AssociatedControl = Me
hwb4.AssociatedControl = Me
hwb5.AssociatedControl = Me
hwb6.AssociatedControl = Me
hwb1.HardwareKey = HardwareKeys.ApplicationKey1
hwb2.HardwareKey = HardwareKeys.ApplicationKey2
hwb3.HardwareKey = HardwareKeys.ApplicationKey3
hwb4.HardwareKey = HardwareKeys.ApplicationKey4
hwb5.HardwareKey = HardwareKeys.ApplicationKey5
hwb6.HardwareKey = HardwareKeys.ApplicationKey6
Catch exc As Exception
MsgBox(exc.Message + " Check if the hardware button is physically available on this device.")
End Try
End Sub
Private Sub ButtonDetection_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown, MyBase.KeyUp

StatusBar2.Text = e.KeyCode


If (e.KeyCode = System.Windows.Forms.Keys.F3) Then
'Enter
KeepOutTimer.Enabled = True
e.Handled = True

End If


' When a hardware button is pressed and released,
' this form receives the KeyUp event. The OnKeyUp
' method is used to determine which hardware
' button was pressed, because the event data
' specifies a member of the HardwareKeys enumeration.
Select Case CType(e.KeyCode, HardwareKeys)
Case HardwareKeys.ApplicationKey1
StatusBar1.Text = "Button 1 pressed."

Case HardwareKeys.ApplicationKey2
StatusBar1.Text = "Button 2 pressed."

Case HardwareKeys.ApplicationKey3
StatusBar1.Text = "Button 3 pressed."

Case HardwareKeys.ApplicationKey4
StatusBar1.Text = "Button 4 pressed."

Case HardwareKeys.ApplicationKey5
StatusBar1.Text = "Button 5 pressed."

Case HardwareKeys.ApplicationKey6
StatusBar1.Text = "Button 6 pressed."

Case Else

End Select

End Sub

Private Sub KeepOutTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles KeepOutTimer.Tick
Me.Show()
End Sub