Author Topic: Key binding problem  (Read 6374 times)

Alessaint

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 67
    • View Profile
Key binding problem
« on: May 27, 2014, 03:00:54 AM »
Hi,

I have a button, that opens ingame menu. It's also bound to gamepad button. Within the ingame menu there is a Back button which closes the menu. It's also bound to the same gamepad button - the idea behind this is that the ingame menu could be opened / closed with the same gamepad button. The problem is, that when I press the button, menu opens and as soon as the newly active Ingame menu's Back button registers the button being held it executes which closes the menu again. Is this intended behavior? Shouldn't Key Bindings be executed only on Key/Button down and not when they become active when the button/key is being held?

Thanks.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Key binding problem
« Reply #1 on: May 28, 2014, 05:33:34 AM »
UIKeyBinding listens to events in Update, meaning if you happen to enable something at the beginning of the Update cycle, it's fully possible that that something will also receive the Update event, and in turn check its own UIKeyBinding. You should either write a script that checks for this, or simply disable the first UIKeyBinding while the window is open.

Alessaint

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 67
    • View Profile
Re: Key binding problem
« Reply #2 on: May 28, 2014, 05:35:40 AM »
I see... Thanks.

Alessaint

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 67
    • View Profile
Re: Key binding problem
« Reply #3 on: May 28, 2014, 06:00:45 AM »
Well, I found the exact reason - Input.GetKeyUp in UIKeyBindings is called even when this button received no GetKeyDown before. I think that this really is a sort of a bug - there is no reason for UIKeyBindings instance to process GetKeyUp without a prior GetKeyDown - I believe that you should add a simple bool check whether the button is pressed otherwise ignore GetKeyUp.

This can happen for instance if you press and hold a button and during this phase another  UIKeyBindings instance bound to the same button gets activated. After the button is released GetKeyUp is executed on both of them.


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Key binding problem
« Reply #4 on: May 28, 2014, 06:07:18 AM »
That seems fair. I'll add the check.

Alessaint

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 67
    • View Profile
Re: Key binding problem
« Reply #5 on: May 28, 2014, 06:19:50 AM »
Great, thanks.