KeyPress event double fires after using MouseWheel

New to Gambas? Post your questions here. No question is too silly or too simple.
Post Reply
JumpyVB
Posts: 75
Joined: Friday 11th September 2020 9:09am

KeyPress event double fires after using MouseWheel

Post 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
vuott
Posts: 263
Joined: Wednesday 5th April 2017 6:07pm
Location: European Union

Re: KeyPress event double fires after using MouseWheel

Post 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. :|
Europaeus sum !

Amare memorentes atque deflentes ad mortem silenter labimur.
JumpyVB
Posts: 75
Joined: Friday 11th September 2020 9:09am

Re: KeyPress event double fires after using MouseWheel

Post by JumpyVB »

vuott wrote: Thursday 6th April 2023 1:53pmIt doesn't happen to me. :|
Whats your gambas and os version?
User avatar
cogier
Site Admin
Posts: 1127
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: KeyPress event double fires after using MouseWheel

Post 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.
JumpyVB
Posts: 75
Joined: Friday 11th September 2020 9:09am

Re: KeyPress event double fires after using MouseWheel

Post 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.
Post Reply