Android Question Bluetooth Button values

james_sgp

Active Member
Licensed User
Longtime User
Hi, I`m connecting B4A to a BT selfie stick and monitoring the key presses (code shown below), but with several keys it returns the correct value but then followed by 5 zero`s. This is making my life hard to detect the keypress, would appreciate any idea`s to help this?

Here is the log:
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
Activity_KeyPress(10)
Camera
Activity_KeyPress(0)
Activity_KeyPress(0)
Activity_KeyPress(0)
Activity_KeyPress(0)
Activity_KeyPress(0)
Activity_KeyPress(11)
Video
Activity_KeyPress(0)
Activity_KeyPress(0)
Activity_KeyPress(0)
Activity_KeyPress(0)
Activity_KeyPress(0)
Activity_KeyPress(66)
Shutter Button clicked
Activity_KeyPress(0)
Activity_KeyPress(0)
Activity_KeyPress(0)
Activity_KeyPress(0)
Activity_KeyPress(0)
Activity_KeyPress(25)
Zoom -
Activity_KeyPress(24)
Zoom +
Activity_KeyPress(24)
Zoom +
Activity_KeyPress(25)
Zoom -
Activity_KeyPress(24)
Zoom +
Activity_KeyPress(25)
Zoom -


B4X:
#Region  Project Attributes
    #ApplicationLabel: B4A Example
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Layout")
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub Activity_KeyPress(KeyCode As Int) As Boolean 'Return True to consume the event
    Log($"Activity_KeyPress(${KeyCode})"$)
   
    If KeyCode = 25 Then
        Log("Zoom -")
        Return True
    End If

    If KeyCode = 24 Then
        Log("Zoom +")
        Return True
    End If
   
    If KeyCode = 11 Then
        Log("Video")
        Return True
    End If

    If KeyCode = 10 Then
        Log("Camera")
        Return True
    End If

    If KeyCode = 66 Then
        Log("Shutter Button clicked")
        Return True
    End If


End Sub
 

DonManfred

Expert
Licensed User
Longtime User
What about ignoring KeyCode 0?
 
Upvote 0

james_sgp

Active Member
Licensed User
Longtime User
Thanks, yes that is what I`m doing now with

B4X:
if keycode = 0 then return true

Just wondering if there is a more efficient way of doing things?
 
Upvote 0

james_sgp

Active Member
Licensed User
Longtime User
Ok, so things don`t seem so straight forward. Using a keytest routine (code below), I catch the 66 keypress (shutter); but using my application I just get zero`s (see below). I really fail to understand why this is happening, any advice would be appreciated.

KEYTEST
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (main) Create, isFirst = false **
** Activity (main) Resume **
Activity_KeyPress(25)
Zoom -
Activity_KeyPress(24)
Zoom +
Activity_KeyPress(11)
Video
Activity_KeyPress(10)
Camera
Activity_KeyPress(66)
Shutter Button clicked
Activity_KeyPress(66)
Shutter Button clicked
Activity_KeyPress(66)
Shutter Button clicked
Activity_KeyPress(66)
Shutter Button clicked

B4X:
Sub Activity_KeyPress(KeyCode As Int) As Boolean 'Return True to consume the event
    If KeyCode = 0 Then Return True
    Log($"Activity_KeyPress(${KeyCode})"$)   
    If KeyCode = 25 Then
        Log("Zoom -")
        Return True
    End If
    If KeyCode = 24 Then
        Log("Zoom +")
        Return True
    End If
    If KeyCode = 11 Then
        Log("Video")
        Return True
    End If
    If KeyCode = 10 Then
        Log("Camera")
        Return True
    End If
    If KeyCode = 66 Then
        Log("Shutter Button clicked")
        Return True
    End If
End Sub

SHUTTER APP CODE
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
/storage/emulated/0/Android/data/b4a.example3/files
FULL
** Activity (main) Resume **
Start success: true
25
25
Zoom -
24
Zoom +
10
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

B4X:
Sub Activity_KeyPress (KeyCode As Int) As Boolean
    Log (KeyCode)
    If KeyCode = 0 Then Return True
    If test_flag = -1 Then
        Return True
    else If test_flag = 1 Then
        test_pnl.Visible = False
        settings_pnl.Visible = False
        test_flag = 0
        Return True
    End If
    If KeyCode = 24 Then
        Log("Zoom +")
        zoom_val = zoom_val + 1
        zoom_bar.Progress = zoom_val * 2
        zoom1(zoom_val)
    else If KeyCode = 25 Then
        Log("Zoom -")
        zoom_val = zoom_val - 1
        zoom_bar.Progress = zoom_val * 2
        zoom1(zoom_val)
    else If KeyCode = 66 Then
        Log("Shutter")
        btnRecord
    else If KeyCode = 11 Then
        Log("Mode")
        btnMode
    else If KeyCode = 10 Then
        Log("Camera")
        btnCamera
    End If
End Sub
 
Upvote 0
Top