Page 1 of 1

KeyPress event double fires after using MouseWheel

Posted: Wednesday 5th April 2023 3:21pm
by JumpyVB
The problem can be reproduced like this:

1) Create new "Graphical application"

2) Add a Button to FMain (we shall call it Button1, no events needed)

3) Paste this code to FMain.class:

Private i As Integer = 0
Public Sub Form_KeyPress()
  If Key.Right Then
    i = i + 1
    Me.Text = CStr(i)
  Endif
End

Public Sub Form_MouseWheel()
  ' Empty on purpose
End


4) Run

5) Try pressing right arrow on the keyboard to increment i by 1

6) Turn the mouse wheel once.

7) Try pressing right arrow on the keyboard and it increments i twice !?!?

8) Click Button1.

9) Try pressing right arrow on the keyboard again and it will increment i by 1

The weird behaviour has something to do with .HasFocus

Am I missing something here or is this a bug that should be reported to Benoit Minisini?

PS: I am using Gambas 3.18.90 on Linux Mint 21.1 Cinnamon 5.6.8

Re: KeyPress event double fires after using MouseWheel

Posted: Thursday 6th April 2023 1:53pm
by vuott
With this your line:
JumpyVB wrote: Wednesday 5th April 2023 3:21pm
If Key.Right Then
I get the increment of the global variable, even if I press the other keys.
So, I propose to use this other line of code:
If Key.Code = Key["Right"] Then ....

JumpyVB wrote: Wednesday 5th April 2023 3:21pm 7) Try pressing right arrow on the keyboard and it increments i twice !?!?
It doesn't happen to me. :|

Re: KeyPress event double fires after using MouseWheel

Posted: Thursday 6th April 2023 2:08pm
by JumpyVB
vuott wrote: Thursday 6th April 2023 1:53pmIt doesn't happen to me. :|
Whats your gambas and os version?

Re: KeyPress event double fires after using MouseWheel

Posted: Thursday 6th April 2023 2:25pm
by cogier
I'm also using Mint 21.1 and the problem you report also happens to me, but I have discovered that this only happens with gb.gui. If you change from GTK to QT using gb.gui.qt instead, the problem goes away. Whether this is a bug in Gambas or in GTK, I leave to others to work out.

Re: KeyPress event double fires after using MouseWheel

Posted: Thursday 6th April 2023 5:27pm
by JumpyVB
cogier wrote: Thursday 6th April 2023 2:25pm I'm also using Mint 21.1 and the problem you report also happens to me, but I have discovered that this only happens with gb.gui. If you change from GTK to QT using gb.gui.qt instead, the problem goes away. Whether this is a bug in Gambas or in GTK, I leave to others to work out.
Thank you for confirming.