Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 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
0
Question by Fragmental · Mar 13, 2017 at 10:37 AM · androidtexturemobileinputfieldtouchscreenkeyboard

How to call a function when mobile keyboard is "done"?

I originally made my app for desktop and this is how I handle a physical keyboard.

  AddTodoField.onEndEdit.AddListener(val =>
         {
                 if (Input.GetKeyDown(KeyCode.Return) || Input.GetKeyDown(KeyCode.KeypadEnter)  )
                 AddTodo();
         });

With this, any time enter is hit, it calls a function which takes the inputfield text and does some stuff with it, and then blanks out the input field.

I tried changing my code to

 if (Input.GetKeyDown(KeyCode.Return) || Input.GetKeyDown(KeyCode.KeypadEnter || TouchScreenKeyboard.done)  )

but it was too good to be true and threw a "an object reference is required to access non-static member TouchScreenKeyboard.done" error.

So I tried assigning TouchScreenKeyboard.done using get component(which I didn't really expect to work, but it was worth a shot)

 private TouchScreenKeyboard keyboard;
 void Start () 
 {
     keyboard = GetComponent<TouchScreenKeyboard>();
 }

and it gave me the error "ArgumentException: GetComponent requires that the requested component 'TouchScreenKeyboard' derives from MonoBehaviour or Component or is an interface."

I've found plenty of documentation for creating a new touchkeyboard, opening the keyboard, and then access "done" from that keyboard, but no documentation for accessing "done" from the touchkeyboard that automatically opens with InputFields.

Does anyone know how to do this? Any help is appreciated.

Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
5
Best Answer

Answer by herDev · Mar 13, 2017 at 01:15 PM

Hi,

Assign a reference to the touchscreen keyboard on your inputfield event and use that to assess if the event is done or not.

Here's a starting point for you:

 private TouchscreenKeyboard mobileKeys;
 
 OnInputEvent()
 {
 mobileKeys = TouchScreenKeyboard.Open("", TouchScreenKeyboardType.default, false);
 }
 
 //Then you can check if the event is done in your Update method or wherever needed
 if (mobileKeys.done)

(The script should go on the input object)
Good luck!

Comment
Add comment · Show 4 · 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 Fragmental · Mar 16, 2017 at 09:46 PM 0
Share

Oh. Oh wow. I actually got it working. I was almost about to give up. Here's the new code:

 private TouchScreen$$anonymous$$eyboard mobile$$anonymous$$eys;
 
 public void OnInputEvent()
 {
     mobile$$anonymous$$eys = TouchScreen$$anonymous$$eyboard.Open("", TouchScreen$$anonymous$$eyboardType.Default, false);
 }
 
 void Start () 
 {
     AddTodoField.onEndEdit.AddListener(val =>
     {
             if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.Return) || Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.$$anonymous$$eypadEnter)  || mobile$$anonymous$$eys.done  )
             AddTodo();
     });

I was kind of confused. I thought OnInputEvent might have been a built-in Unity function(it's not). And I had to fix some capitalization(no big deal). Then I wasn't sure what I was supposed to do with the OnInputEvent() function. I checked my Input field and it already had a Unity script called "Event Trigger" I had added to it with an event type of "Select". So I aded OnInputEvent() to that and everything worked.

Thank you so much for your answer! I couldn't have done it without you.

avatar image herDev Fragmental · Mar 20, 2017 at 07:57 AM 0
Share

Great, glad you got it working! Best of luck with the app

avatar image WaldyIgnat Fragmental · May 24, 2018 at 01:38 PM 0
Share

very nice it works fine for me too !!

avatar image Fragmental · Mar 16, 2017 at 09:47 PM 0
Share

BTW. Nice avatar. Love that show.

avatar image
1

Answer by levilais · Oct 22, 2021 at 09:41 PM

It's not the exact same thing - but if you're using TMP_InputField, you can do this:

private void OnEnable() { var _inputField = GetComponent(); _inputField.onTouchScreenKeyboardStatusChanged.AddListener(ProcessDonePressed); }

 void ProcessDonePressed(TouchScreenKeyboard.Status newStatus)
 {
     Debug.Log("Done Pressed");
 }

 private void OnDisable()
 {
     var _inputField = GetComponent<TMP_InputField>();
     _inputField.onTouchScreenKeyboardStatusChanged.RemoveListener(ProcessDonePressed);
 }
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 damianallison · Feb 10 at 08:24 PM 0
Share

This worked for me. Thanks. (For anyone else, here's the full code I ended up using to check specifically for the Status.Done)

 public TMP_InputField inputField;
 
 Awake()
 private void OnEnable() {
     inputField.onTouchScreenKeyboardStatusChanged.AddListener(ProcessDonePressed);
 }
 
 private void OnDisable() {
     inputField.onTouchScreenKeyboardStatusChanged.RemoveListener(ProcessDonePressed);
 }
 
 void ProcessDonePressed(TouchScreenKeyboard.Status newStatus) {
   if (newStatus == TouchScreenKeyboard.Status.Done) {
        Debug.Log("Done Pressed");
    }
 }

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

143 People are following this question.

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

Related Questions

Disabling the inputfield above the keyboard or disable it all 0 Answers

Android, slicing up textures bigger than max size? 1 Answer

Blue looks like teal on mobile? 0 Answers

Keep input field caret active when focused on mobile devices in addition to native input field caret 0 Answers

Android water texture 1 Answer


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