Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Morgan · May 12, 2015 at 10:28 PM · iphonetouchscreenkeyboardmobile keyboardascii

How to use TouchScreenKeyboardType with the new 4.6+ UI System?

I can't seem to find any relevant examples. (I'm using JavaScript FWIW.)

I'm assuming it's a property specific to a given InputField component, or some other UI component, but my best guess fails:

 var myField : UI.InputField;
 
 ...
 
 myField.TouchScreenKeyboard.TouchScreenKeyboardType = TouchScreenKeyboardType.ASCIICapable;

I can control myField successfully in many ways, but this line just generates BCE0019: 'TouchScreenKeyboard' is not a member of 'UnityEngine.UI.InputField'.

(Ultimate goal: prevent Emoji entry. I'm assuming that's what "ASCIICapable" does.)

TIA

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

1 Reply

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

Answer by Bunny83 · May 13, 2015 at 01:22 AM

TouchScreenKeyboard is a class. So the way you try to use it makes no sense at all ^^.

InputField has a property called keyboardType which allows you to specify which keyboard type it should use. So you can do:

 myField.keyboardType = TouchScreenKeyboardType.ASCIICapable;




Comment
Add comment · Show 3 · 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 Morgan · May 13, 2015 at 03:50 AM 0
Share

Thanks! I was trying to guess the property name, but when it didn't match the class name, and searching the InputField docs for "TouchScreen$$anonymous$$eyboard" came up blank, I was stumped!

Happy to say, I'm now Emoji-free :) (And as I'd hoped, accents are still allowed even if not technically ASCII.)

avatar image Bunny83 · May 13, 2015 at 10:32 AM 1
Share

If you have problems inputting non ASCII characters you might use the default keyboard but filter the input and only allow characters you want. The InputField has a delegate called onValidateInput. It takes the current text, the position in the text and the new character as parameter and you should return the character that will be added.

Even though it's not mentioned in the docs i'm sure when you return character 0 ('\0') it won't add anything and you filtered the input out.

You can use a dictionary or array of allowed / forbidden characters to check if a certain character is allowed.

 public char OnValidateInput(string text, int charIndex, char addedChar)
 {
     if (!allowedChars.Contains(addedChar))
         return '\0';
     if (forbiddenChars.Contains(addedChar))
         return '\0';
     return addedChar;
 }
 
 myField.onValidateInput += OnValidateInput;


If you use a dictionary you might want to use Contains$$anonymous$$ey ins$$anonymous$$d. Of course you can do whatever you want inside that callback. Just keep in $$anonymous$$d that it's called for each character you type.

avatar image Morgan · May 13, 2015 at 09:35 PM 0
Share

Thanks! I just wanted a keyboard that can type exactly what Unity is capable of rendering--which includes accents, so I've avoided the need for validation.

(I have not begun to explore supporting non-Latin character sets/languages, and I can't imagine it's easy to support, say, Chinese, but that's a project for another day!)

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

20 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

Related Questions

How to bring up the mobile keyboard on Iphone 1 Answer

TouchScreenKeyboard not working with GUI.TextArea (tested with Android tablet) 0 Answers

TMP InputField does not fire onTouchScreenKeyboardStatusChanged event when keyboard becomes visible 0 Answers

2 different cameras 2 Answers

How can I create collision detection? 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