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 sdgd · Feb 13, 2014 at 04:32 AM · c#bug-perhapskeydownany

How to change anyKey in to anyKeyDown? with proper inputString.

this is the problem I'm heaving:

IF I press

 a

I get Debug:

 false:  Length: 0

For code:

 void Update(){
     if (Input.anyKeyDown){
         Debug.Log("false: " + Input.inputString + " Length: " + Input.inputString.Length);
         if (Input.inputString.Length == 1){
             Debug.Log("true: " + Input.inputString);
         }
     }
 }

IF I press

 a

I get Debug:

 false: a Length: 1
 true: a

For Code:

 void Update(){
     if (Input.anyKey){
         Debug.Log("false: " + Input.inputString + " Length: " + Input.inputString.Length);
         if (Input.inputString.Length == 1){
             Debug.Log("true: " + Input.inputString);
         }
     }
 }

This works perfectly EXCEPT I want to fetch only key downs, .... How should I do that?

In the last code I also GET

  • 1X false: a Length: 1

  • 1X true: a

  • 2X false: Length: 0

Comment
Add comment · Show 10
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 whydoidoit · Feb 13, 2014 at 04:38 AM 0
Share

Hmmm, yep the input string will be updated on 'Up' not on 'Down', what are you after doing?

avatar image sdgd · Feb 13, 2014 at 04:40 AM 0
Share

I'm working on GUI3D

everything already works perfectly even "Layout" but this gives me huge problems, right now.

avatar image whydoidoit · Feb 13, 2014 at 04:43 AM 0
Share

So you really need 'Down' not 'Up'?

avatar image sdgd · Feb 13, 2014 at 04:45 AM 0
Share

yes I really need down

think how strange it would look like if you pressing something would yield after up and not down.

if it would be for me I could go with up but it's not for me, ...

AND this is in the Update

EVEN $$anonymous$$ORE!!!

there's no any$$anonymous$$eyUp in Input. ...

avatar image Scribe · Feb 13, 2014 at 05:39 AM 1
Share

This doesn't appear to work with 'system keys', things like delete and ctrl and such but does seem to work with backspace and letters and quite a few others:

 var onDown : boolean = false;
 var inputString : String;
 
 function Update () {
     if (Input.any$$anonymous$$eyDown){
         onDown = true;
     }
     
     if(onDown && Input.inputString.Length != 0){
         inputString = Input.inputString;
         onDown = false;
     }
 }

It does seem very strange that its not possible to access Input.inputString from the any$$anonymous$$eyDown input.

Scribe

Show more comments

1 Reply

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

Answer by sdgd · Feb 13, 2014 at 07:00 AM

Finally after trying and trying, ... I finally figured out how should I do it, ...

thanks to @whydoidoit and @Scribe

I learned the complete machanics behind it, ... so what I did is:

 bool OnDown = false;
 void Update(){
     if (OnDown){
         // my code
         OnDown = false;
     }
     if (Input.anyKeyDown){
         onDown = true;
     }
 }

so it actually has to pass 1 FRAME in order to get the character in, ...

and no @whydoidoit I couldn't do only with

 Input.inpusString > 0

because there was lots of inputs that take 1 length like backslash, enter/return, ... Witch are mostly collected before, ... and lots of them that take 0 like delete and even more of them, ....

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

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

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Renderer on object disabled after level reload 1 Answer

GameObject Rotation with KeyDown applied only for a frame. 1 Answer

#if 0 causing a Unity 2018.2.2f1 freeze on Mac OS X 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