Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
4
Question by jdonzet · Mar 05, 2015 at 12:23 AM · uiinputfieldfocustouchscreenkeyboardkeyboardevent

Keep InputField focus / selected when clicking a button / touch screen /UI 4.6

I am programming an ingame keyboard to be used in windows standalone. I want to use an InputField as the target for the user input. The problem is the InputField lost focus when a button is clicked (in this case the button represents a keyboard key) and it does´t catch correctly the key that i send.

To simulate keyboard key pressed events I use this:

inputField.ProcessEvent(Event.KeyboardEvent("a ")); where "a" represents the a key.

I tried using inputField.ActivateInputField(); and inputField.Select(); in different ways but it didn't solve my problem.

Do anyone know how to solve this? Thanks

Full code

 /* "a" BUTTON CLICK HANDLER    , I also tried putting it inside Update()*/                    
 inputField.Select();   // I also tried to use this EventSystem.current.SetSelectedGameObject(go);
 inputField.ActivateInputField();
 inputField.ProcessEvent(Event.KeyboardEvent("a"));
Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image carcas20 · Mar 20, 2015 at 05:48 AM 0
Share

how solve the problem?

avatar image silentdudeZA · Jun 02, 2015 at 10:57 AM 0
Share

still nothing on this question? I'm experiencing a similar issue.

2 Replies

· Add your reply
  • Sort: 
avatar image
5

Answer by bstevens · Jan 24, 2017 at 10:24 AM

You should create a new script that inherits from Unity's InputField class and overrides the OnSelect and OnDeselect methods. This will disable the default behaviour and maintain focus on the InputField:

 using UnityEngine;
 using UnityEngine.UI;
 using UnityEngine.EventSystems;
 
 public class FocusInputField : InputField {
 
     public override void OnSelect(BaseEventData eventData)
     {
         Debug.Log ("Overrides InputField.OnSelect");
         //base.OnSelect(eventData);
         //ActivateInputField();
     }
 
     public override void OnDeselect(BaseEventData eventData)
     {
         Debug.Log ("Overrides InputField.Deselect");
         //DeactivateInputField();
         //base.OnDeselect(eventData);
     }
 
 }

Add a InputField UI element to the scene, remove the default InputField component and add your new class FocusInputField as a new component.

Remember to add the Text component and Placeholder references as these will be missing when you add the FocusInputField component.

The modified component should look like this in the inspector:

alt text

You can then use something like this on a UI button to send keystrokes to the InputField. Note the call to inputField.ForceLabelUpdate():

 using UnityEngine;
 using UnityEngine.UI;
 using System.Collections;
 
 public class TestKeyboardButton : MonoBehaviour {
 
     public FocusInputField inputField;
     private Button btn;
 
     void Start () {
         btn = GetComponent<Button> ();
         btn.onClick.AddListener (OnClick);
     }
     
     void OnClick () {
         inputField.ProcessEvent(Event.KeyboardEvent("a"));
         inputField.ForceLabelUpdate ();
     }
 }



screen-shot-2017-01-24-at-093124.png (91.1 kB)
Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image QECZA · Aug 10, 2018 at 03:19 AM 0
Share

@bstevens Great helpfull for me. I can now input characters via custom buttons, and it works well but the character '#'. I can not input '#' by 'inputfiled.ProcessEvent(Event.$$anonymous$$eyboardEvent("#"))'. It says '#' = Shift in unity document, i wonder how to input the symbol '#' using keyboardevent, any help?Thanks.

avatar image doanlinhit24 · Jun 22, 2021 at 04:09 AM 0
Share

good chóp. it works with me. Thanks @bstevens

avatar image
-1

Answer by nitry33 · Apr 17, 2015 at 09:59 AM

You solved the issue? Another question is about inputField used, how you close the unity touchscreenkeyboard for displaying yours?

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image SweatyChair · Oct 11, 2018 at 09:18 AM 0
Share

U should use the comment if you not answering the question.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Make android number pad keyboard visible for TMPro_InputField 0 Answers

TouchScreenKeyboard Issue - iOS (iPad) 0 Answers

Cannot Hide Android keyboard when inputfield activated 1 Answer

[tvOS] UI.InputField doesn't show touchscreenKeyboard automatically 1 Answer

InputField instance isFocused always return false. 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges