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
1
Question by Trent · Jul 20, 2010 at 07:43 AM · cursorkeyboardtextfieldlocation

Moving the keyboard cursor position to the end of a TextField

I'm working on a chat GUI at the moment and I stumbled across an interesting issue that I haven't been able to figure out. If I use am searching for a particular string and replacing with something else, the cursor stay at the previous location in the string. For example:

chatEntryValue = GUI.TextField(new Rect(y, x, w, h), chatEntryValue);
chatEntryValue = Regex.Replace(chatEntryValue ,"^/s ", "/Squad ");

The resulting cursor position will be (pipe as the cursor position) [/Sq|uad ]

I've tried using chatEntryValue.Remove(1,1) & chatEntryValue.Insert(1,"Squad ") with the same results and even gone so far as unfocusing off the TextField and containing window and refocusing.

Does anyone out there know of a way to move the cursor to the end of the TextField? I'd even settle for simulating Right arrow key presses on the keyboard.

Any help would be appreciated!

Comment
Add comment · Show 1
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 mrde · Jun 20, 2013 at 09:25 PM 0
Share

Look here, excellent example http://answers.unity3d.com/questions/210808/using-guifocuscontrol-on-textfield-selects-all-tex.html

6 Replies

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

Answer by qJake · Jul 20, 2010 at 09:03 AM

Looking around, unfortunately there is no way to move the text cursor around inside a Text Area or Textbox. You can get the current position of the cursor, but you cannot set it.

I would suggest this feature be added using the "Report bug" feature inside of Unity. There is an option there for suggesting new features.

And, perhaps, this functionality has been added in Unity 3, which is due out any time now. You could always wait and see if they've included it in there or not. As of right now, though, it looks like this isn't possible.

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

Answer by YasinJavaid_ · Mar 29, 2017 at 07:19 AM

late but someone may help. inputfeild.MoveTextEnd(false);

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

Answer by lcairco · Dec 02, 2013 at 05:56 PM

This works for me, where s is the string in the text box:

 TextEditor editor = (TextEditor)GUIUtility.GetStateObject(typeof(TextEditor), GUIUtility.keyboardControl);
 
 editor.selectPos = s.Length + 1;
 editor.pos = s.Length + 1;
Comment
Add comment · 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
3

Answer by valdemar · May 10, 2011 at 12:31 PM

TextEditor te = (TextEditor)GUIUtility.GetStateObject(typeof(TextEditor), GUIUtility.keyboardControl); if (te != null) { te.MoveCursorToPosition(new Vector2(5555, 5555)); }

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

Answer by Bill 2 · Sep 10, 2010 at 02:52 PM

how do you get the current position of the cursor?

Thanks

Comment
Add comment · 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
  • 1
  • 2
  • ›

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Editable text field in Android with cursor 0 Answers

Textfield button PLZ HELP!!! 1 Answer

Use specific TouchScreenKeyboardType for different text fields 3 Answers

Need to Find Distance Between Mouse Cursor and Object in a 2.5D SideScroller 1 Answer

Disabling the inputfield above the keyboard or disable it all 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