Android Question B4A - Problem Keyboard of device

stefano cavallari

Member
Licensed User
Longtime User
Good morning,
the keyboard of my terminal has a key that allows you to change the keyboard from numeric to alphanumeric (or vice versa).
For my application I need to know if that key has been pressed or not and if the keyboard is only numeric or not.

I tried to use the Activity_KeyPress event and it actually tells me if that key has been pressed, but it doesn't tell me what type of keyboard I have.
It also happens that the keycode of a text character for example @ is the same as KeyCodes.KEYCODE_2

I hope I explained myself.
I thank you in advance for your help
 

stefano cavallari

Member
Licensed User
Longtime User
This (link below) doesn't seem to agree with what you've written.. so maybe something else is going 'wrong' with your code.. https://developer.android.com/reference/android/view/KeyEvent

They mention KEYCODE_2 and KEYCODE_AT...

Thanks for the reply, I try to give you some more information

I put a log to see what the keycode takes.
If I put a breakpoints in the log line and then scroll through the instructions one by one the app works.
If I don't have breakpoints, keycode first assumes the value 59 and then the value 9 which is equal to that of the keycodes.KEYCODE_2.

This is the code :


B4X:
Sub Activity_KeyPress (KeyCode As Int) As Boolean
    Dim bResult As Boolean = False
    CallSubDelayed3(Me, "ProcessKeyPress", KeyCode, bResult)
    Return bResult
End Sub

Sub ProcessKeyPress(keycode As Int, Result As Boolean)
    '    handle the back key
    If(keycode = 284) Then 'This is the button that changes the keyboard'
        Return
    End If

    'Scelta is a int '
    scelta =-1
    Log(keycode)
    Select keycode
        Case KeyCodes.KEYCODE_0
            scelta = 0
        Case KeyCodes.KEYCODE_1
            scelta = 1
        Case KeyCodes.KEYCODE_2
            scelta = 2
        Case KeyCodes.KEYCODE_3
            scelta = 3
        Case KeyCodes.KEYCODE_4
            scelta = 4
        Case KeyCodes.KEYCODE_5
            scelta = 5
        Case KeyCodes.KEYCODE_6
            scelta = 6
        Case KeyCodes.KEYCODE_7
            scelta = 7
        Case KeyCodes.KEYCODE_8
            scelta = 8
        Case KeyCodes.KEYCODE_9
            scelta = 9       
    End Select
end sub


Most likely, I'm wrong, but I don't understand what.
 
Upvote 0

eps

Expert
Licensed User
Longtime User
Can you put a Case for KeyCodes.KEYCODE_AT in the code and see what happens - you can use log or toast message to display the values or interaction.. Are you checking scelta or KeyCodes where you have the issue? If scelta then don't think it will change as you haven't got a KEYCODE_AT part in there... or is that a snippet of code?

Of Course I'm not actually sure what you're trying to achieve here, as it feels little wrong...
 
Upvote 0

stefano cavallari

Member
Licensed User
Longtime User
Can you put a Case for KeyCodes.KEYCODE_AT in the code and see what happens - you can use log or toast message to display the values or interaction.. Are you checking scelta or KeyCodes where you have the issue? If scelta then don't think it will change as you haven't got a KEYCODE_AT part in there... or is that a snippet of code?

Of Course I'm not actually sure what you're trying to achieve here, as it feels little wrong...

I'm working on "scelta".
The app was developed in this way, I have a menu, the user can access the menu either by moving through the arrows and pressing ENTER or using the physical keyboard and pressing the item numbers.
So I don't use the virtual keyboard that opens for example with an edit text.
The voice of menu are labels.

Menu example:
0 - EXIT
1 - START
2 - WRITE
3 - READ

For example, if the operator wants to "read", he simply presses 3 on the keyboard.

I only put a piece of code, not all of it ,because it would be too long.
Copying them to a new file gives me the same problem anyway.

Also I followed your advice in the select I also put the case for AT but it does not enter the same.
 
Upvote 0

eps

Expert
Licensed User
Longtime User
Ah right, so it's a device with an actual keyboard.. So you want to process 2 as 2, which works and @ as...2? or nothing? I'm not sure what you are expecting @ to do, or do you mean that it shouldn't be processed?

What device is this?
 
Upvote 0

stefano cavallari

Member
Licensed User
Longtime User
Ah right, so it's a device with an actual keyboard.. So you want to process 2 as 2, which works and @ as...2? or nothing? I'm not sure what you are expecting @ to do, or do you mean that it shouldn't be processed?

What device is this?


Exactly, device with actual keyboard.

I actually would like a way to understand if the operator has pressed that key on the keyboard in order to understand if he has changed the keyboard from numeric to alphanumeric, so I can then do the related checks.


The device is an Android EDA50K
 
Upvote 0

eps

Expert
Licensed User
Longtime User
I don't get how they 'change the keyboard' if it's a physical device? Surely it's just a keyboard? Maybe with a combination of keypresses, but just a keyboard.
 
Upvote 0

stefano cavallari

Member
Licensed User
Longtime User
I don't get how they 'change the keyboard' if it's a physical device? Surely it's just a keyboard? Maybe with a combination of keypresses, but just a keyboard.

The keyboard is for example like that of an old cell phone, that is, the numbers are written on it, however if you press the shift or function key (in my case it is a blue key), instead of writing the numbers write the characters.

What I want to know is if the user has pressed that "blue button" and now uses characters instead of numbers, because for the main menu I want him to use only numbers.
 
Upvote 0

eps

Expert
Licensed User
Longtime User
Have you been able to 'trap' that keypress? It looks like a non-standard key of some kind... Probably worth asking on the Honeywell website - as the device seems to be one of theirs...
 
Upvote 0

stefano cavallari

Member
Licensed User
Longtime User
I guess the device doesn't have a touchscreen?

Yes, I managed to understand what code has the "blue button" has a key code = 284, my doubt is this:
if they press the button during the application I can make sure to notice it, but if they press that button while the application is closed, when they open my app a message should appear "Warning, the keyboard is not numeric"

The terminal has a touchscreen but at the customer's request it must not be used
 
Upvote 0

eps

Expert
Licensed User
Longtime User
Without having access to your App or the device it's hard to help on this one, as it is specific to this device. You may well be able to force the App to open the keyboard in a specific state or check the state of the keyboard. But it's a bit of a guessing game.
 
Upvote 0

stefano cavallari

Member
Licensed User
Longtime User
Without having access to your App or the device it's hard to help on this one, as it is specific to this device. You may well be able to force the App to open the keyboard in a specific state or check the state of the keyboard. But it's a bit of a guessing game.

Yes, I see.
Exactly for what I wrote here, to find out if there was any procedure or library that would allow me to manage the state of the "physical keyboard".
 
Upvote 0

eps

Expert
Licensed User
Longtime User
I think you need to read this and check the Honeywell documentation...


ETA :

To respond to modifier key events such as when a key is combined with Shift or Control, you can query the KeyEventthat's passed to the callback method. Several methods provide information about modifier keys such as getModifiers() and getMetaState(). However, the simplest solution is to check whether the exact modifier key you care about is being pressed with methods such as isShiftPressed() and isCtrlPressed().
 
Upvote 0
Top