Results 1 to 7 of 7

Thread: [RESOLVED] Assigning Hardware buttons

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2009
    Location
    Hawaii
    Posts
    24

    Resolved [RESOLVED] Assigning Hardware buttons

    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.

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

  2. #2
    Frenzied Member
    Join Date
    Oct 2005
    Posts
    1,286

    Re: Assigning Hardware buttons

    try
    e.handled = true
    after the 'Up
    that should ignore it
    Pete Vickers
    MVP - Device Application Development
    http://www.gui-innovations.com http://mobileworld.appamundi.com/blogs/

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Apr 2009
    Location
    Hawaii
    Posts
    24

    Re: Assigning Hardware buttons

    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/For...-aa75ce614350/
    might be what im looking for..just trying to figure it all out..

  4. #4
    Frenzied Member
    Join Date
    Oct 2005
    Posts
    1,286

    Re: Assigning Hardware buttons

    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
    Pete Vickers
    MVP - Device Application Development
    http://www.gui-innovations.com http://mobileworld.appamundi.com/blogs/

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Apr 2009
    Location
    Hawaii
    Posts
    24

    Re: Assigning Hardware buttons

    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

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

  6. #6
    Frenzied Member
    Join Date
    Oct 2005
    Posts
    1,286

    Re: Assigning Hardware buttons

    hi,
    Take a look at this video from Jim Wilson and see if it helps
    Pete Vickers
    MVP - Device Application Development
    http://www.gui-innovations.com http://mobileworld.appamundi.com/blogs/

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Apr 2009
    Location
    Hawaii
    Posts
    24

    Re: Assigning Hardware buttons

    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.

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

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width