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
1
Question by zckhyt · Nov 25, 2015 at 08:52 PM · c#unity 5inputupdatekeycode

How to Use Key Combinations with the Control-Key?

In the Unity 5 editor, when I try to give input in Update with a control-key mod, the key-press of another key is not rightly registered.

If I have:

 void Update()
 {
         if ((Input.GetKey(KeyCode.RightControl) || Input.GetKey(KeyCode.LeftControl)) &&          
              Input.GetKey(KeyCode.X)) Debug.Log(true);
 }

And my input is: Left-Ctrl + X, nothing is printed. Same with Right-Ctrl + X.

However, if I have Shift + Ctrl + X, then "true" is printed! By not specifying "right" or "left," I mean to imply it does not matter which is the case.

And Alt + Ctrl + X also prints "true"

This is true for all the letters on a standard keyboard in-place of X, it would seem after testing a few.

However, if I have

 void Update()
 {
         if ((Input.GetKey(KeyCode.RightControl) || Input.GetKey(KeyCode.LeftControl)) &&                             Input.GetKeyDown(KeyCode.Alpha1))) Debug.Log(true);
 }

By pressing a Ctrl-Key alone will solicit the output: "true"

I have no problem integrating the control-keys with mouse clicks nor shift or alt with other keys, so what is happening here that is messing with the input so?

Edit: I want to clarify that it works when I build the project, but as noted at the beginning this weird, and I hesitate to call it a bug, "bug" only exists in the editor. I'm trying to find a way around it.

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 ttesla · Nov 27, 2015 at 09:08 AM 1
Share

I guess Ctrl key is caught by Unity editor which causes weird behaviors as you described. Try to use Ctrl + P key. It will start/stops the editor player. I confirm the code above. If you first press X then Ctrl, it works but if you first Ctrl then X, it never reads the X key. It is something with Editor I guess, it should work fine in builds.

2 Replies

· Add your reply
  • Sort: 
avatar image
-1

Answer by TStudios13 · Dec 01, 2019 at 11:55 PM

@zckhyt

Try this

if (Input.GetKey(KeyCode.RightControl) { if (Input.GetKey(KeyCode.LeftControl) { Debug.Log(true); }

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 ErikH2000 · Feb 14, 2021 at 07:51 PM

There are some answers over here - https://answers.unity.com/questions/49285/how-can-i-get-a-combination-of-keys-pressed.html?_ga=2.23479418.1148461192.1613246522-1228664066.1589857462

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

(Game Build) Validating files and updating to latest version 0 Answers

Why Do Inputs Have to Been in Update (Rather than FixedUpdate)? 3 Answers

Key not recognized 2 Answers

How do i Update a Transforms Position, and how do i have objects face along a spline?? 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