Author Topic: Focus for Enter key  (Read 3686 times)

KeithT

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 55
    • View Profile
Focus for Enter key
« on: April 17, 2012, 05:28:52 AM »
Is there a built in way to control which widget/button gets fired when the enter key is pressed ?

Closest have found is the code in the chat window script, but not obvious how to use generically.

Thanks in advance for any insights.


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Focus for Enter key
« Reply #1 on: April 17, 2012, 05:34:54 AM »
Here's what I do: inside the Start() function on the "LoginPage" script, I set up which functions will be receiving the OnSubmit type notifications (when enter is pressed):

  1. loginField.eventReceiver = gameObject;
  2. loginField.functionName = "OnLoginField";
  3. passwordField.eventReceiver = gameObject;
  4. passwordField.functionName = "ValidateFields";

OnLoginField function is simple:

  1. void OnLoginField () { passwordField.selected = true; }

ValidateFields() performs the actual validation and does something else, like show a new window or load a new scene.

KeithT

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 55
    • View Profile
Re: Focus for Enter key
« Reply #2 on: April 17, 2012, 06:22:24 AM »
Thanks for the response, but think we are at cross purposes.

The problem we have is that we have windows with buttons that popup acknowledgement windows when the button is clicked, with for example an "ok" button them. The problem we have is that UICamera caches the last button that was clicked and if you hit "Enter" it reruns the button click which opens the acknowledgement window a 2nd time. We could trap this in the button handler and ensure the window is only opened once, but would prefer to set the focus of the "Enter" key press to be the "ok" button on the acknowledgement window.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Focus for Enter key
« Reply #3 on: April 17, 2012, 06:03:43 PM »
It does what now? OnClick is sent only once.