B4J Code Snippet B4XDialog - Add keyboard handling

Discussion in 'B4J Code Snippets' started by Erel, Apr 7, 2019.

  1. Erel

    Erel Administrator Staff Member Licensed User

    This code allows the user to close the dialog with 'escape' or one of the following keys: Y, N or C.
    It depends on agraham's jReflection library.

    Sub AddKeyPressedListener
    Dim r As Reflector
       r.Target = MainForm.RootPane
    End Sub

    Sub KeyPressed_Event (e As Event)
    If Dialog.Visible Then
    Dim jo As JavaObject = e
    Dim keycode As String = jo.RunMethod("getCode"Null)
    If keycode = "ESCAPE" or keycode = "C" Then
    Else If keycode = "Y" Then
    Else If keycode = "N" Then
    End If
    End If
    End Sub
    You need to call AddKeyPressedListener once when the program starts.
  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