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
2
Question by NarallandaKaratoga · Jun 22, 2018 at 02:04 PM · inputkeyboardkeyboard inputkeys

Check if there is a keyboard input (not a specified key input)

Since Input.anyKey indicates mouse input as well, and Input.inputString only contains visiable characters, I can't find out the way to check whether there is a keyboard input correctly except for checking KeyCode one by one.
So what's the correct way to do so?

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
0
Best Answer

Answer by LeeroyLin · Jun 22, 2018 at 02:08 PM

 // Press A
 if(Input.GetKeyDown(KeyCode.A)){
 }

 // Press A always
 if(Input.GetKey(KeyCode.A)){
 }

 // Don't press A anymore
 if(Input.GetKeyUp(KeyCode.A)){
 }




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 NarallandaKaratoga · Jun 23, 2018 at 10:24 AM 0
Share

This is what "checking $$anonymous$$eyCode one by one"... And I have to test hundreds of keys just like that... So there isn't any better idea?

avatar image LeeroyLin NarallandaKaratoga · Jun 23, 2018 at 10:50 AM 0
Share

O$$anonymous$$, I know what you mean. Use this.

 public void OnGUI()
 {
     if (Input.any$$anonymous$$eyDown)
     {
         Event e = Event.current;
         if (e.is$$anonymous$$ey)
         {
             Debug.Log("Current $$anonymous$$ey is : " + e.keyCode.ToString());
         }
     }
 }

avatar image NarallandaKaratoga LeeroyLin · Jun 23, 2018 at 12:43 PM 0
Share

Tested and yes that's what I want! Thanks a lot.

Show more comments
avatar image
0

Answer by DevJeeth · Jul 30, 2019 at 06:31 AM

This isn't what was asked for and this is exactly what I am looking out for too. Any key pressed on the keyboard should be detected. Input.anyKey includes mouse click unfortunately.

LeeroyLin just specifies the keycode here

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 DevJeeth · Jul 30, 2019 at 06:49 AM 0
Share

I have worked on a work around, looked into the docs https://docs.unity3d.com/ScriptReference/$$anonymous$$eyCode.html

 if(!Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.$$anonymous$$ouse0) 
             && !Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.$$anonymous$$ouse1)
             && !Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.$$anonymous$$ouse2)
             && !Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.$$anonymous$$ouse3)
             && !Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.$$anonymous$$ouse4)
             && !Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.$$anonymous$$ouse5)
             && !Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.$$anonymous$$ouse6))
         {
             if (Input.any$$anonymous$$eyDown)
             {
                 Debug.Log("<color=red> $$anonymous$$ey board key pressed</color>");
             }
         }



Hope it helps somebody, if anyone got a better way to do this please do update this

avatar image shieldgenerator7 DevJeeth · Apr 17, 2020 at 09:57 PM 0
Share

I tried to use the anonymous thing, but it didn't work, and the link you psoted is broken. I suspect that Unity has since deprecated this functionality.

avatar image Bonfire-Boy shieldgenerator7 · Apr 17, 2020 at 10:10 PM 1
Share

See my earlier reply to you under the other answer. This page has got corrupted, ignore all the anonymous nonsense - they're all just supposed to be 'K'!

avatar image NarallandaKaratoga · Aug 02, 2019 at 11:46 AM 0
Share

it seems that the comments are lost, which is exactly the answer. look at this: https://docs.unity3d.com/ScriptReference/Event.html And then I shall get Event.current.keyCode in OnGUI, and do whatever I would.

avatar image Bonfire-Boy NarallandaKaratoga · Aug 02, 2019 at 04:18 PM 0
Share

Event has an is$$anonymous$$ey property, not used it myself but it sounds like it might help

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

104 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

Related Questions

input manager not working correctly? 0 Answers

Issues with Input.inputString 2 Answers

How to change the editor's keyboard to AZERTY layout? 1 Answer

simulate pc keyboard input in android touch screen keyboard 0 Answers

Unity input system: TapInteraction does not produce a value when using ReadValue() 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