B4J Tutorial [BANano] Events

Discussion in 'B4J Tutorials' started by alwaysbusy, Dec 4, 2018.

  1. alwaysbusy

    alwaysbusy Expert Licensed User

    BANano has a simple system to use events:

    HandleEvents: does the same as On, BUT prevents the default behaviour
    On
    : handles one or more events
    Off: disables an event

    To explain the difference between HandleEvents and the On() call, here is an example:

    (1)
    Code:
    Dim inp As BANanoElement = BANano.GetElement(".inputkeys")
    inp.On(
    "keydown", EventHandler, "inp_keydown"' we do want the origi!nal event still to work
    inp.HandleEvents("keyup", EventHandler, "inp_keyup")
    (2)
    Code:
    Dim inp As BANanoElement = BANano.GetElement(".inputkeys")
    inp.HandleEvents(
    "keydown", EventHandler, "inp_keydown"' we do want the origi!nal event still to work
    inp.HandleEvents("keyup", EventHandler, "inp_keyup")
    They look very similar, but they behave differently:

    In (1), it does go to the inp_keydown we wrote, and it does add the letter to the input field.
    In (2), it does also go to inp_keydown, but it does not add the letter to the input field

    (2) makes it simple to e.g. make a mask. This for example prevents the user from entering a letter a:

    Code:
    public Sub Inp_KeyDown(event As BANanoEvent)
       
    Log(event.ID & " Keydown: " & event.Key)
       
    If event.Key = "a" Then
           
    event.PreventDefault
       
    End If   
    End Sub
    Alain
     
    Erel and Kiffi like this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice