Android Question Help! I need to know the source of Activity_KeyPress()

wonder

Expert
Licensed User
Longtime User
Regarding the DPAD KeyCodes (KEYCODE_DPAD_RIGHT, KEYCODE_DPAD_LEFT, KEYCODE_DPAD_UP and KEYCODE_DPAD_DOWN), if I have both a physical keyboard and a physical game controller plugged-in at the same time, Activity_KeyPress(KeyCode As Int) will get the same KeyCode value.

In other words, pressing DOWN on the keyboard or pressing DOWN on the gamepad will always yield the same result, which is NOT what I want.

Here's what I need:
B4X:
Sub Activity_KeyPress(KeyCode As Int) As Boolean    
    Select KeyCode    
        Case KeyCodes.KEYCODE_DPAD_DOWN
            Log("The DOWN key was pressed by the user, but on which device?")
            Select getKeyPressSource '<-- This is the magical function that I need!!!!!!!!
                Case KEYBOARD
                    Log("The key was pressed on physical keyboard")
                    Exit
            
                Case GAMEPAD
                    Log("The key was pressed on the physical gamepad")
                    Exit

                Case Else
                    Log("The key was pressed on an unknown device")
                    Exit
    
            End Select    
            ...
            ...
            ...
            ...


Can anyone help me wrire a "getButtonPressSource" method?

Many many thanks in advance!
 
Last edited:

Cableguy

Expert
Licensed User
Longtime User
the thing is, most game pads use a keyb emulation....

I guess you'll need to write your own gamepad drivers so that you can get different results
 
Upvote 0

wonder

Expert
Licensed User
Longtime User
the thing is, most game pads use a keyb emulation....

I guess you'll need to write your own gamepad drivers so that you can get different results
That can't be true, because some games allow 2-player mode using physical controllers.
This means that the game knows how to differentiate between a keypress on Controller 1 and a keypress on Controller 2...
 
Upvote 0
Top