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 united4life · May 08, 2013 at 10:26 AM · inputkeyinput.getkey

How to check which key i have pressed?

i want to check which key i have pressed. So inside Debug.Log()… what should i write? If i am pressing K … K should come in the console window.

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

3 Replies

· Add your reply
  • Sort: 
avatar image
3

Answer by chelnok · May 08, 2013 at 01:21 PM

 if(Input.anyKey)
 {
      Debug.Log(Input.inputString);
 }
Comment
Add comment · Show 2 · 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 united4life · May 08, 2013 at 01:27 PM 0
Share

if i am writing Debug.Log(Input.inputString); and pressing $$anonymous$$.... in the console window it is co$$anonymous$$g $$anonymous$$ and 10 times blank debug.

avatar image chelnok · May 08, 2013 at 02:11 PM 0
Share

interesting.. i havnt actually ever used that nothing but debugging reasons, and never thought it much more. I tried, and you are right about it. Sorry, dont know any other tricks, but check this one: http://answers.unity3d.com/questions/369542/retriving-double-index-from-input-string.html

avatar image
0

Answer by SubatomicHero · May 08, 2013 at 11:10 AM

 void Update()
 {
     if (Input.GetKeyUp("k"))
     {
         Debug.Log("K was pressed");
     }
 }
Comment
Add comment · Show 1 · 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 united4life · May 08, 2013 at 11:12 AM 0
Share

like this.

 if(Input.any$$anonymous$$ey)
 {
      Debug.Log();           //Here i have to print which key was pressed
 }
avatar image
0

Answer by pgomes · Jul 08, 2014 at 04:39 PM

In certain cases you might want to use the following:

 void OnGUI() {
    Event e = Event.current;
    if (e.isKey)
       Debug.Log("e.keyCode: "+e.keyCode);
 }

I was trying to understand the button output of a peripheral recognized as a keyboard (wireless presenter), and Input.inputString didn't help me because it was returning an empty string for non printable characters such as PageUp.

Comment
Add comment · Show 2 · 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 chelnok · Jul 08, 2014 at 05:09 PM 0
Share

that works, however i get two log entry every time i press a key; one for the key, and another one "e.keyCode: None" ..just curious, any idea why? Some sort of reset event in background..?

avatar image Fappp · May 06, 2015 at 07:11 PM 0
Share

$$anonymous$$ake sure you use it in a OnGUI.

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

15 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

Related Questions

Get numeric key 4 Answers

GetKey/GetButton not working if 2 Adjacent keys are being pressed at the same time 1 Answer

Is there a way to get precise input ? 1 Answer

key remaping menu 0 Answers

How to handle Key + Mouse Wheel simultaneously? 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