B4J Question TextField - handle TAB as Enter

DarkoT

Active Member
Licensed User
Hi guys,
need little help...
How can I handle Tab same as Enter; I need to get txtfield_Action when user move WITH TAB from one field to another... With Enter works perfect, I can not figure out how to catch Tab... I'm using B4J Pages for desktop app...
Need example... Help, please...


Tnx, DaT
 

emexes

Expert
Licensed User
Perhaps the _FocusChanged event, although that would be triggered by anything that leaves the field, not just the Tab key = might be better or worse, depending on what you're trying to achieve.

 
Upvote 0

DarkoT

Active Member
Licensed User
I hope somebody will help this example...

If you want to get info about keypress from textBox, here is a simple code with comments:

Example - KeyPress:
'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    
    ' initpage (adding colors, fonts, dimensions, ...)
    InitPage

    ' adding controle for Tab keypress for all textboxes on page
    ControleTab(txtZaposleniKoda)
    ControleTab(txtDNKoda)

End Sub

' adding controle over keypress as reflector
Public Sub ControleTab(ctl As Object)
    'allow Escape key to exit signin screen
    Dim r As Reflector
    r.Target = ctl
    r.AddEventFilter("keypressed","javafx.scene.input.KeyEvent.KEY_PRESSED")
End Sub

' filter all keypress on textbox
Sub KeyPressed_Filter (e As Event)
    Dim jo As JavaObject = e
    Dim keycode As String = jo.RunMethod("getCode", Null)
    If keycode = "TAB" Then
        Log("tab")
    Else
        Log(keycode)
        e.Consume
    End If
End Sub
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…