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
2
Question by depth · Apr 07, 2013 at 08:05 PM · inputcontrolgetkey

having trouble with "ctrl + number"

ive been having a problem with ctrl and a number not running the lines of code inside the braces.

it wont work inside the editor or after a build to an EXE.

i found someone having the same trouble and tried there solution but it didn't seem to work for me.

i have also tried plugging in a USB keyboard to see if it's my laptop thats causing the trouble. still same problem.

 if (Input.GetKey(KeyCode.LeftControl) && Input.GetKeyDown(KeyCode.Alpha1))
     {
     print("Doesn't print this");
     }


or

 if (Input.GetKeyDown("1"))
 {
     ControlGroup(1);
 }
 
 
 void ControlGroup (int number)
     {
         if ((Input.GetKey (KeyCode.LeftControl)) || (Input.GetKey (KeyCode.RightControl))) 
         {
             switch(number)
             {
                 case 1:
                 print ("Doesn't print this either");
                 break;
             }
 

any ideas what i'm missing?

many thanks in advance

Comment
Add comment · Show 11
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 Nidre · Apr 08, 2013 at 06:20 AM 0
Share

Try this;

  if (Input.Get$$anonymous$$ey($$anonymous$$eyCode.LeftControl) | Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.Alpha1)) 
avatar image AlucardJay · Apr 08, 2013 at 06:46 AM 0
Share

This is most strange, you are absolutely correct. I just did a test in uJS, and it had the exact problem you are describing. I even tried checking for a string ins$$anonymous$$d of a keycode enum :

 function Update() 
 {
     if ( Input.Get$$anonymous$$ey( $$anonymous$$eyCode.LeftControl ) )
     {
         Debug.Log( "LeftCtrl Detected" );
         
         if ( Input.Get$$anonymous$$eyDown( $$anonymous$$eyCode.Alpha1 ) )
         {
             Debug.Log( "LeftCtrl and Alpha1 Detected" );
         }
         
         if ( Input.Get$$anonymous$$eyDown( "1" ) )
         {
             Debug.Log( "LeftCtrl and String 1 Detected" );
         }
     }
 }

Upvoting question.

avatar image Nidre · Apr 08, 2013 at 07:10 AM 0
Share

No i haven't tested actually.I just written that the same way i do for Windows applications on C# so i thought this might help :)

By the way i have no idea why you are telling that :)$$anonymous$$y point was using | ins$$anonymous$$d of ||(Cause in c# apps(Wİndows form actually) this usage works for access modifier keys.(Ctrl + X + X...)

There is no problem using extra parenthesis, as long as they encapsulate the appropriate items.

avatar image Nidre · Apr 08, 2013 at 07:19 AM 0
Share

Well as i said i didn't mentioned "(" so the change was simply "||" that to "|" according to the general c# usage.

I wouldn't change parenthesis and send this as an answer :)

avatar image AlucardJay · Apr 08, 2013 at 07:35 PM 1
Share

$$anonymous$$y next method to test would then be to use the Input $$anonymous$$anager, map the Ctrl key to a button, then use Input.GetButton.

Here are the results of a search I just did for you to look through (untested, just searched) :

  • http://answers.unity3d.com/questions/214611/command-for-holding-a-key-down-shift-key.html

  • http://answers.unity3d.com/questions/49285/how-can-i-get-a-combination-of-keys-pressed.html

  • http://answers.unity3d.com/questions/264010/ctrlkey-combination-not-working-properly.html

  • http://answers.unity3d.com/questions/9223/how-can-i-check-to-see-if-a-button-combination-is.html http://forum.unity3d.com/threads/138386-How-can-i-check-if-multiple-keys-is-pressed-down-at-once

If my Input $$anonymous$$anager suggestion, or something in one of those works, please let us know.

Show more comments

1 Reply

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

Answer by AnomalusUndrdog · Apr 08, 2013 at 09:04 AM

Try this:

 void OnGUI()
 {
     Event e = Event.current;
     if (e.isKey && e.control && e.keyCode == KeyCode.F)
     {
         Debug.Log("ctrl + F");
     }
 }

Unofrtunately this has to be done in OnGUI. Take note Ctrl + 1 seems to be a hotkey that Unity already uses so it won't get detected when running in the Unity Editor. I'll try to see if there's some other way to detect Control + some key in Update.

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 depth · Apr 08, 2013 at 07:29 PM 0
Share

Thanks for the help, but i couldn't get that to work. not sure what was up with it but it was not happy.

EDIT

ok, read the undertext again, and yes, it worked with the f (not the 1 though)

i did try and run the core bits in Update but it error'd...

NullReferenceException: Object reference not set to an instance of an object

TeamShipAndCommands.Update () (at Assets/_Scripts/TeamShipAndCommands.cs:45) line 45 being the if but i can still have a play. having a look at changing Event.current to Event.$$anonymous$$eyboardEvent. many thanks :D EDIT (again) wont run in update as it's a GUI thing. works though. thankyou :) http://docs.unity3d.com/Documentation/ScriptReference/Event.$$anonymous$$eyboardEvent.html

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

12 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

Related Questions

How to make camera position relative to a specific target. 1 Answer

Unity C# Two keys pressing one after another not doing a function vice versa 0 Answers

Input.GetKey not working 1 Answer

Control left + right = up 0 Answers

Send Keys to Background Window 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