- Home /
Keyboard Ctrl + 1 Input Problem
Is there a way to handle grouping keyboard inputs like Ctrl+[numeric]? Example: Ctrl+1, Ctrl+2, etc.
I've tried the following:
if(Input.GetKey("left ctrl"){
if(Input.GetKeyDown("1"){
Debug.Log("Ctrl+1 Down");
}
}
If I change the "left ctrl" to a "left alt" then there aren't any problems, otherwise it seems like Control is blocking access to the other characaters.
Alt is already bound to another action so it'd be really nice if I could use Ctrl.
Answer by JMGoebel · Jul 18, 2012 at 10:29 PM
It is a very simple and logical solution and that is why it was a problem. ( The easy ones always cause the most problems!)
if(Input.GetKey(KeyCode.LeftControl) && Input.GetKeyDown(KeyCode.S))
{ // Do what ever you need }
In your case use KeyCode.Alpha1
I found that this will NOT work in the unity editor because CTRL is used for other things within the editor. However, when you build and run your application it will work just as expected.
I hope this helps!
Wow... I completely forgot about this question. This was posted like 2 years ago. Honestly I can't remember if I ever figured this out so I'll accept the answer since you rightly identify that Unity's editor blocks the use of ctrl in preview.
Answer by DonutOfTime44 · May 20, 2013 at 08:50 PM
Your syntax is incorrect...
if(Input.GetKey("left ctrl")){
if(Input.GetKeyDown("1")){
Debug.Log("Ctrl+1 Down");
}
}
-1
and this is not an answer. Why do you revive such an old question which has already been solved without adding any useful information?
btw: the syntax isn't wrong at all. $$anonymous$$aybe you've ment the function parameter but it's not syntax, it's just data.
Answer by Simon V · Jun 01, 2011 at 08:32 PM
Try using Input.GetKeyDown(KeyCode.LeftControl) instead.
No luck it seems.
Tried: if( Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.LeftControl)){ if(Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.Alpha0)||Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.$$anonymous$$eypad0)){Debug.Log("Ctrl + 1 is down"); } }