Android Question B4XPages Delegate.Activity_KeyPress(KeyCode) not passing keycode to showing page

Robert Valentino

Well-Known Member
Licensed User
Longtime User
Having trouble getting the Activity_KeyPress(KeyCode) to the current page.

1622582209261.png


My scores routine has a special looking dialog that kind of looks numeric key pad showing that I need to handle / pass the 0 -> 9 keys
Normally the user just taps the keypad and that works fine. But I am trying to handle users that want to have a wireless keypad.

My goal would to know if they have a wireless keypad/keyboard and handle the keys or taps on the screen.

In my main I have
B4X:
Sub Activity_KeyPress(KeyCode As Int) As Boolean
        If  mPagesManager.IsInitialized Then       
#if Debug           
            LogColor($"Main::Activity_KeyPress - Key:${KeyCode}"$, Colors.Green)            
#end if
            Return B4XPages.Delegate.Activity_KeyPress(KeyCode)                                       
        End If
   
    Return False   
End Sub

But the ActivityKeyPress in the scores / showing page doesn't get called

B4X:
'  Code from Page Scores which is showing when doing this test

Public Sub Activity_KeyPress(KeyCode As Int) As Boolean
            LogColor($"${DEFINE_PageName}::Activity_KeyPress -  Key:${KeyCode}"$, Colors.Green)

            If  mNumericKeyPad.IsInitialized And mNumericKeyPad.IsShowing Then
                Return mNumericKeyPad.KeyPress(KeyCode)
            End If
   
            Return false
End Sub

I can force Main to send the keycode to the right page but getting the proper page and calling it

This code works. But is not the right way to pass the key strokes - because the scores page is not always showing.

I thought B4XPages.Delegate.Activity_KeyPress(KeyCode) would pass the keycode on to the active / showing page

B4X:
Change main code to 

Sub Activity_KeyPress(KeyCode As Int) As Boolean
        If  mPagesManager.IsInitialized Then       
#if Debug           
            LogColor($"Main::Activity_KeyPress - Key:${KeyCode}"$, Colors.Green)            
#end if

            Dim Scores As pFWScores = B4XPages.GetPage(cBBsGlobals.DEFINE_PageName_FWScores)
            Return Scores.Activity_KeyPress(KeyCode)
        End If
    Return False   
End Sub


How do I pass the keycode correctly - is delegrate.activity_keypress not the right way

Thanks for any help
 

Robert Valentino

Well-Known Member
Licensed User
Longtime User
Confusing.
I thought that calling B4XPages.Delegate.Activity_KeyPress(KeyCode)
would pass the keycode on to my Page if I should get it (maybe not passing back key) and if I didn't handled the key (return false) then it would move up the line

But OK, will handle it like the example.
 
Upvote 0
Top