var times = 0;
function Update ()
{
if(Input.GetKeyDown("m"))
{
times++;
if(Input.GetKey("left shift") || Input.GetKey("right shift"))
{
Debug.Log("M has been clicked "+ times + "time(S)! this time it was shift and m!");
}
else if ( Input.inputString == "M")
{
Debug.Log("caps and m were pressed!");
}
else
{
Debug.Log("M has been clicked "+ times + "time(S)! this time it was just m!");
}
}
}
This code can distinguish between caps and m, shift and m, or just plain m.
The first script will only work if m is the only thing pressed.
You would better use blabla.ToLower().Contains(“m”) there to check if m is one of the currently pressed keys.
Or alternatively something in the way of Input.GetKey(Keycode.Key_M)
Then the script likely is never executed.
You can test that with a small Debug.Log(“test test”); at the beginning of the function. if the log shows no test test then the function is never called, be it because the object is inactive, because the component is inactive or because the component isn’t present at all in that scene
I agree with the above, step 1 would be to ensure that your script is getting called at all, perhaps testing with Input.anyKey or Input.anyKeyDown once you’re sure it’s executing. This will help sort out if the script getting triggered at all is the issue or if it’s the key detection in particular.
Ok. I add this debug message to the Update() function. Now “test test” flooding the console, and still work only “Input.inputString == “m””, but “Input.GetKey(“m”) || Input.GetKey(KeyCode.M)” won’t work
Here my code:
function Update () {
// Debug.Log("test test");
if(Input.GetKey("m") || Input.GetKey(KeyCode.M)) {
Debug.Log("Look, this works!");
}
if ( Input.inputString == "m" )
Debug.Log("input = m");
}
I can see “input = m” in console, but never see “Look, this works!”. Have you idea how find this bug. Probably I should setup smth in project settings?
Interesting thing that old project (FPS Tutorial for instance I remember sometime ago I could move with a,s,d,w key, but now only with keyboard arrow) it won’t work too.
And no, I don’t have any concrete ideas as your code works perfectly for me. Do you have a different language setting/configuration that could have your system “confused” as to what key is actually being pressed? Is it only “m” that fails or do other keys produce similar results?
Just an idea… As there are two debugs in that latest code, could one debug be wiping the other off the screen? Perhaps you should open the full debug window (if you have not all ready) and check for both?
sorry, but this is big problem for me. I can’t work with keyboard press in nomral way. Is there are any debug message or smth like this to understand you and me where is the problem lay?
I use russian and english both, but I see message from Input.inputString that user press ‘m’, and it works ok, problem appear with GetKey or even GetAxis if there are alphabetic key.
Could this problem appear I upgrade Unity 2.4 to 2.5?
To be brutally honest that doesn’t matter one iota, there is no reason to yell. We’re here trying to help you but are not at your personal beck and call, we too have jobs, work and other things to attend to. So please, go easy on us!
Read Flynn’s reply above, test against other keys, test on other machines, more data is needed. So far we have perfectly fine code failing for one key on one machine. Test a few variations and let’s see what comes of that (different keys, different language settings, different machines, etc.)
Where did you get Unity 2.4???
It might help but I’m doubtful as this wasn’t a specific issue in 2.1 AFAIK. But apart from this issue I think you ought to upgrade anyway as 2.5 offers plenty o’ benefits.
So what I could find.
There are no problem with unity 2.5 or project which I produce on other computer. Even if I made web player GetKey become work in correct way. So the problem in my Unity Editor or configuration of it.
Do you think it could help if I reinstall unity (do I have problem with activate unity with my key if I reinstall it)?