[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: capture keycode in valuefield



Am 18.06.24 um 11:18 schrieb Bruce Steers:


On Tue, 18 Jun 2024 at 01:18, Bruce Steers <bsteers4@xxxxxxxxx> wrote:



    On Tue, 18 Jun 2024 at 00:42, Bruce Steers <bsteers4@xxxxxxxxx> wrote:



        On Tue, 18 Jun 2024 at 00:11, Dag JNJ <gambas@xxxxxxxxxxxx> wrote:

            Hi,

            I wanted to jump between fields in the GUI using Enter,
            Return, Down- and Up-Arrows. In textbox-fields it. it
            works, like this:

            /Public Sub FLD_vorgabe_tbx_KeyPress()

              If Key.Code = Key.Enter Or Key.Code = Key.Return Or
            Key.Code = Key.Down Then FLD_kommentar_tba.SetFocus
              If Key.Code = Key.Up Then FLD_nachkomma_vbx.SetFocus

            End/

            All 4 keys are captured. But in a valuebox field only
            enter and return are captured.

            /Public Sub FLD_nachkomma_vbx_KeyPress()

              If Key.Code = Key.Enter Or Key.Code = Key.Return Or
            Key.Code = Key.Down Then FLD_vorgabe_tbx.SetFocus
              If Key.Code = Key.Up Then FLD_laenge_vbx.SetFocus

            End/

            Do I make something wrong, or are the capturing of
            arrow-keys left out for some reason? (I tried with other
            keys too, none seem to work).

            Thankful for any hint, kind regards, Dag


        I found only up and down arrow keys get swallowed and do not
        fire the event but left and right keys do.

        I wonder if there is code to make up and down keys adjust the
        value but it is not working?
        For whatever the reason up and down key events seem to be
        eaten by the control.
        The wiki does explain that some non-native controls can
        swallow key events, this is one of those cases.

        Respects
        BruceS



    You can do this simple override (i think it works okay and does
    not effect the ValueBox workings)..
    you will have an intercept for Key events before the ValueBox sees
    them
    and if in the FMain.class you Stop the ValueBox_KeyPress event the
    ValueBox should not see it.......

    Save the following text as a file called ValueBox.class in your
    projects .src folder

    -------------snip----------------
    ' Gambas class file ValueBox.class

    Export
    Event KeyPress

    Public Sub NumberBox_KeyPress()

      Dim bStop As Boolean
      bStop = Raise KeyPress
      If bStop Then
        Stop Event
        Return
      Endif

      Super.NumberBox_KeyPress ' this line may not be needed

    End
    --------------snip-------------

    That allows you things like this in FMain...

    Public Sub ValueBox1_KeyPress()

      If Key.code = Key.Up Then
        Inc ValueBox1.Value
        Stop Event
      Else If Key.code = Key.Down Then
        Dec ValueBox1.Value
        Stop Event
      Endif

    End

    Respects
    BruceS


I have had a similar issue a few times with a few different controls where i wanted to handle/see all the key events before the control did and had to find a workaround for it as by default there was no way. It would be good i think if all controls had something like a Control.KeyPressFirst property so ANY Control / UserControl that has that set will use the above bStop type syntax to raise the KeyPress event first so you can see ALL Key events before the control gets the chance to eat it and also you can Stop the control seeing it if you want.

Respects
BruceS
Works perfect, thank you.

All the best,

Dag

References:
capture keycode in valuefieldDag JNJ <gambas@xxxxxxxxxxxx>
Re: capture keycode in valuefieldBruce Steers <bsteers4@xxxxxxxxx>
Re: capture keycode in valuefieldBruce Steers <bsteers4@xxxxxxxxx>
Re: capture keycode in valuefieldBruce Steers <bsteers4@xxxxxxxxx>