Input and Input needed :)

Hello,

I want to detect keyboard input but for some reason it dosent work? Does anyone know how to do this? It seems sooo simple but Just wont work know matter what I try to do? Ok here it is:

I want to hold down the mouse button then when I press the W key have a Debug.Log(“is it working”).

I can do the reverse like this: (holding the W key and press the mouse button Debug.Log(“Yes this works”)

if(Input.GetAxis("w")  Input.GetKeyDown("mouse 0"))
		{
			Debug.Log("Yes this works");
		}

Is it possible to do what I want above? and if so how would I code it? if not is there a reason why its not possible? Im thinking maybe Im missing something simple or Ive just been at it way to long today lol

if anyone knows how to do this Please let me know :smile:

Well, I think for starters you might try Input.GetKey (“w”) instead of GetAxis. Also, GetKeyDown only works for the frame in which the key is pressed, better for firing things etc. where you want a single action to occur. GetKey returns true as long as the user holds down the key, which in this case is what you want since the user may press the keys at different times.

Hello tool55 I’ve tried GetKey and GetKeyDown but whats strange is if your holding down the mouse button and you want to get a message when you hit W, I can’t get any message like Debug.Log(“something”); and I just cant figure out how to do this. Any chance you got it to work? or anyone else run into something like this?

Alright!!!

After yet another round of a process of elimination I got it :smile:

if(Input.GetKey(KeyCode.Mouse0)  Input.GetKeyDown(KeyCode.W))
   		{
   			//Why is this not working?
   			Debug.Log("Printtttttt");
   		}

The first one needed to be GetKey Only, then GetKeyDown etc… YAY! Thank you tool55 I must have missed the first one and I kept trying to change the second Input of W when all this time it was the first one of Mouse0 lol.

Its the simple things that get ya!

Looks good. Glad you got it working. I’ll have to play with it when I get a chance.:slight_smile:

FWIW, if you are delivering via a web player, Unity’s keyboard input does not work on Mac OS in Safari or Chrome (works in Firefox). I don’t know of any workaround, other than hoping it gets fixed in the next update.

I’ve noticed that Chrome, in particular, seems to be very glitchy with Unity Webplayer. Even mouse movements stop working after a while. I’m sure the Unity folks are working to fix these issue (at least I hope so)