Android Question How to intercept or simulate first tab key press

LuigiTasca

Member
Licensed User
Longtime User
Hello,
Some time ago I developed on my application a barcode scanning. I do this intercepting the chars with activity_keypress and when I receive the tab key my application search the barcode.
It works, but I got a problem that my customer reject. The application starts to read the barcode after the first time, because it starts to read the chars after some view lost the focus because of the tab key.
I need to read from the first scan. How can I set the "focus" on the reading on activity_keypress, at the program start? Or how can i simulate the first tab key press to remedy the problem?

Thank you
 

Star-Dust

Expert
Licensed User
Longtime User
I do not know if I understood the problem well.
But from what I understand you open the keyboard immediately after starting the App.

I would do so maybe, but you must try it:
B4X:
Sub Activity_Create(FirstTime As Boolean)
......
   Dim K As IME
   K.Initialize("")
   K.ShowKeyboard(Activity)
End Sub
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
I would do this to simulate the tab key at startup

B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    Activity_KeyPress(KeyCodes.KEYCODE_TAB)
End Sub
 
Upvote 0

LuigiTasca

Member
Licensed User
Longtime User
I make you an example
I would do this to simulate the tab key at startup

B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    Activity_KeyPress(KeyCodes.KEYCODE_TAB)
End Sub

No, It wouldn't work.

I make you an example:
  1. I start my activity. I don't know where focus is set (I don't need a focused view).
  2. I read a barcode with my scanner (with tab as terminator char)
  3. Application does not intercept the chars in anyway. But after that it reads the tab char is like the focus has setted like I need.
  4. From now the scans pass in the activity_keypress and I can intercept them.

I need something that set the "focus" on the activity_keypress.
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
Focus is an event of views, it is not a function of events.
KeyPress is already an event of a Vista, and Focus is another event related to a view.

Unfortunately I do not understand what you need, I can not help you. Sorry
 
Upvote 0

LuigiTasca

Member
Licensed User
Longtime User
Focus is an event of views, it is not a function of events.
KeyPress is already an event of a Vista, and Focus is another event related to a view.

Unfortunately I do not understand what you need, I can not help you. Sorry

Ciao Stardust, ho appena visto che sei italiano!
Provo a spiegarmi meglio...
Non riesco ad intercettare la prima lettura del barcode all'avvio del programma. Dopo la prima lettura le successive le leggo normalmente, intercettando l'evento keypress. Uso come carattere di fine lettura il tab.

Ho lo stesso problema anche quando ho il focus su un edittext, finché non leggo il carattere tab e la view perde il focus l'evento activity_keypress non si scatena. Questo ovviamente perché l'evento viene intercettato dall'edittext. Questo non è un problema ma a parer mio è lo stesso motivo per cui non intercetto quello all'avvio.

Non so come far perdere automaticamente il focus all'eventuale view che mi intercetta l'evento e che non ho ancora identificato.

Grazie
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
Please open the same post in the Italian forum, because English is required. So I can answer you in Italian

With which scanner do you read the barcode? With the device's camera?
 
Upvote 0
Top