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 /
This question was closed Jul 06, 2014 at 10:35 PM by QuestionAsker for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by QuestionAsker · Nov 05, 2013 at 05:03 AM · textcharacterstringtextfieldfield

How to check if control is pressed in a text field?

I need to be able to see if control is pressed while entering in keys into a string in a textfield. I'd like to do something like this, maybe in hexadecimal notation

if (c == 0xA2)

An extensive hour and half of googling yielded no results. Do you know how to do this? Thanks!

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 Huacanacha · Nov 05, 2013 at 05:13 AM 0
Share

I'm fairly certain it's not possible as there are no callbacks available for the built in GUI elements, the most any of them give you is the return value which I assume won't include any of the control key presses. In fact the GUI elements in Unity operate quite strangely in my opinion... I know they are planning an overhaul for Unity 4.3 based in part on the NGUI package (the guy that wrote NGUI went to work for Unity to fix their GUI!). Hopefully we'll see some more sensible design with more flexible control...

avatar image QuestionAsker · Nov 05, 2013 at 01:07 PM 0
Share

I hope so! I can't believe you can't do just check like that. Well thank you, I am going to use the timer idea. Its should work perfectly for now. Thank you

2 Replies

  • Sort: 
avatar image
1
Best Answer

Answer by Jamora · Nov 05, 2013 at 01:44 PM

This is how I'd basically check if ctrl was pressed while a text field was focused. It'll register every frame ctrl is pressed, so if the intention is to react once to pressing ctrl (i.e. Input.GetKeyDown type of behavior) then additional checks need to be added.

 GUI.SetNextControlName("CtrlField");
 myString = GUILayout.TextField(myString);
         
 if(Event.current.control && GUI.GetNameOfFocusedControl().Equals("CtrlField"))
     Debug.Log("ctrl pressed while textfield focused");
Comment
Add comment · Show 5 · 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 QuestionAsker · Nov 05, 2013 at 04:19 PM 0
Share

That works wonderfully!!!!!! Thank you so much!

avatar image QuestionAsker · Nov 05, 2013 at 04:30 PM 0
Share

Is there a way to check if its left or right control?

avatar image Jamora · Nov 05, 2013 at 06:50 PM 0
Share

Yes. Change your if-clause:

 if(Event.current.keyCode == $$anonymous$$eyCode.LeftControl && GUI.GetNameOfFocusedControl().Equals("CtrlField"))
avatar image QuestionAsker · Nov 05, 2013 at 10:05 PM 0
Share

That's perfect! Thank you! Is there a detailed documentation on that subject? Some times the official documentation is very lacking.

avatar image Jamora · Nov 06, 2013 at 05:33 AM 0
Share

There's only the official documentation that I know of.

I see you've asked a lot of questions, but haven't marked any as answered. You should press the tick mark below the thumbs to mark the most correct/helpful answer as the solution. Gives the answerer a warm and fuzzy feeling and a few points.

avatar image
1

Answer by Zaeran · Nov 05, 2013 at 05:31 AM

 if(Input.GetKey(KeyCode.LeftControl)){
     //stuff to do when control is pressed
 }
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 Huacanacha · Nov 05, 2013 at 05:41 AM 0
Share

Right, but how can they check that this is happening whist the user is editing the text field? I'm curious about this myself now.

One (poor) manual hack way could be to set a timer each time the text input changes, and if recently changes assume the text field is in focus.

avatar image Zaeran · Nov 05, 2013 at 06:57 AM 0
Share

you make a good point. I suppose you just keep a temp string of the textbox input, and put in a if(tempString != Textbox.text){//if ctrl pressed}.

avatar image Huacanacha · Nov 05, 2013 at 07:05 AM 0
Share

It may also be worth looking at NGUI in the Asset Store... there's a free version to start with. That might provide the level of control needed to do this (if it indicates which field has focus or provides proper callbacks on key presses etc).

avatar image QuestionAsker · Nov 05, 2013 at 01:04 PM 0
Share

Hm. I've had literally no complaints before with Unity. I need to write my own mock control key stuff because I want it changed in the main menu. I do like the idea of the timer however. This will be rough, but that will do fine. Thank you everyone!

Follow this Question

Answers Answers and Comments

17 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

Related Questions

How do i take a string from a gui and show it in the gameworld c# 1 Answer

Taking data from text file 2 Answers

Rich text character-by-character shows tags. How to hide them? 2 Answers

For loop on text without effecting each other 1 Answer

particle system position on top of string position 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