current event not detecting shift key

well, I believe the subject says everything.

Event.current.keyCode returns 0, but current.shift returns true.

It happens on editor and win stand-alone.

void OnGUI() {
        Debug.Log("Event.current.keyCode: " + Event.current.keyCode);
        Debug.Log("Event.current.shift: " + Event.current.shift);
}

Sorry for my english !!!

I think you’ve found a genuine issue here - I’ve reported it.

thanks, but are you sure? perhaps is just some windows configuration.

I tried it on a Mac and it didn’t work there either :wink:

In any case, the documentation should probably warn you that this problem can happen.

This is still happening in 3.4

I just ran into this issue as well in version 4.0… anyone got an idea for a solution?

still same on 4.0.1

but I’ve found a Partionally solution if anyone is interested I’m kinda playing with this about 2 days

	string asd;
	Event e = Event.current;
	if (e.shift){
		asd = "L/R Shift";
	}

my full getting keys code is:

	public string asd;
	public string delta;
	public int asdf = 0;
	public int rev = 0;
	void OnGUI(){
		
		
		
		

		Event e = Event.current;
		
			if (e.shift){
    		    Debug.Log("Pressed: " + e.commandName);
			}
		if (e.delta.ToString() == "(0.0, -3.0)"){
			rev++;
			if (rev > 1){asdf--; rev=0;}
			asdf++;
		}
		
		if (e.delta.ToString() == "(0.0, 3.0)"){
			
			rev--;
			if (rev < -1){asdf++; rev=0;}
			asdf--;
		}
		
		
		
		
		if (e.delta.ToString() != "(0.0, 0.0)"){
			delta = e.delta.ToString();
		}
		
		
		
		if (e.functionKey || e.isKey || e.isMouse || e.command || e.shift){
			if (e.keyCode.ToString() != "None"){
				asd = e.keyCode.ToString();
			}
			else if (e.shift){
				asd = "L/R Shift";
			}
		}
}

about mouse wheel I’ll probably have to tweak it a bit so I won’t need to make reverse divide by 2

and in inspector you can clearly see how are key pressed

don’t know if I’ll still find this post to repair it when I improve my key fetching

am about shift I figured out with first statement up there he gave me idea how to fetch shift

Got it all working as a charm

using UnityEngine;
using System.Collections;

public struct KeyBindings {
	public string Keys;
	public bool DontTurnOffToggle;
	
	public void UseSpecialKeysF (){
		
	}
	
	public void CatchAllKeysF () {
		DontTurnOffToggle = true;
		
		// input needs every code to be found and set to string while event finds it him self
		Event e = Event.current;
		
		if (Input.anyKey || e.functionKey || (e.type.ToString() == "scrollWheel")){ // SysReq (Print Screen)  scrollWheel don't work on any key
			
			// this keys don't work on Event.current so we do imputs first
			// we catch all mouse buttons (even if event has first 3 mouse buttons)
			for (int i=0; i < 6  (Keys != "/") ; i++) {
				if (Input.GetMouseButton(i)){
					Keys = "Mouse Button " + i;
					DontTurnOffToggle = false;
				}
			}
			
			if (e.shift){// we check with Event if shift is down
				if (Input.GetKey(KeyCode.LeftShift)){	// we check with input witch shift is down
					Keys = "Left Shift";
					DontTurnOffToggle = false;
				}
				else if (Input.GetKey(KeyCode.RightShift)){// we check with input witch shift is down
					Keys = "Right Shift";
					DontTurnOffToggle = false;
				}
			}
			
			// we must catch 2 input keys Ĺľ  < as otherwise both will become backslash
			else if (Input.GetKey(KeyCode.Backslash)){
				Keys = "/";
			}
			
			// Events starts
			// we catch all Keyboard keys
			else if (e.keyCode.ToString() != "None"  (! (Input.GetKey(KeyCode.Backslash) ||
																Input.GetKey(KeyCode.Return) )  )  ){// (! Input.GetKey(KeyCode.Backslash)) is here if they fix this it works even without this witch shouldn't
				Keys = e.keyCode.ToString();
				DontTurnOffToggle = false;
			}
			
			// we catch MouseWheel Forward/Backward
			else if (e.delta.ToString() == "(0.0, -3.0)"){
				Keys = "scroll Wheel Forward";
				DontTurnOffToggle = false;
			}
			else if (e.delta.ToString() == "(0.0, 3.0)"){
				Keys = "scroll Wheel Backward";
				DontTurnOffToggle = false;
			}
			// OVERRIDER
			if (Keys == "/"  Input.GetKey(KeyCode.Return)){
				DontTurnOffToggle = false;
			}
			if (Keys != "/"  Input.GetKey(KeyCode.Return)){
				Keys = e.keyCode.ToString();
				DontTurnOffToggle = false;
			}
		}
	}
}






/* only notes left not everything works out of box some things need to get some public variables to make them work
 * 																	(espacelly to see them working in inspector)
		//learning type of events
		
		catching all keys:
		
		
		
		
		// event way (doesn't get Mouse keys 3+)
		if ((e.type.ToString() == "KeyDown") || (e.type.ToString() == "mouseDown") || (e.type.ToString() == "scrollWheel")
				|| e.shift || e.functionKey){} // Shift  SysReq (Print Screen) don't work on "KeyDown"
		
		
		// input way
		if (Input.anyKey || e.functionKey || (e.type.ToString() == "scrollWheel")){} // SysReq (Print Screen)  scrollWheel don't work on any key
		
		
		if ((e.type.ToString() != "Repaint")  (e.type.ToString() != "Layout")){
    	    Debug.Log("Pressed: " + e.type);
		}
//		 * Event.current.Type
//		 * KeyDown		is doing continuously
//		 * KeyUp		is doing 2 times at releace
//		 * mouseDown	only once
//		 * mouseUp		only once
//		 * mouseDrag	when mouse is down and you are draging it it's updated only for each dragging
//		 			*	it's stopped when no dragging even if mouse down
//		 * scrollWheel	on mouse wheel
//		 * 
//		 * used			when I press a button
		
		//catching mouse buttons 1-3
		if (e.isMouse){
			Keys = e.button.ToString();
		}
		
		//catching mousewheel forward // is calles on begin and end so I did a / 2 with ++/--rev
		if (e.delta.ToString() == "(0.0, -3.0)"){
			rev++;
			if (rev > 1){Keysf--; rev=0;}
			Keysf++;
		}
		//catching mousewheel backward
		if (e.delta.ToString() == "(0.0, 3.0)"){
			
			rev--;
			if (rev < -1){Keysf++; rev=0;}
			Keysf--;
		}
		
		
		
		// figureiing out delta
		if (e.delta.ToString() != "(0.0, 0.0)"){
			delta = e.delta.ToString();
		}
		
		
		// catching all keyboard controlls
		if (e.functionKey || e.isKey || e.isMouse || e.command || e.shift){
			if (e.keyCode.ToString() != "None"){
				Keys = e.keyCode.ToString();
			}
			else if (e.shift){
				Keys = "L/R Shift";
			}
		}
*/

if anyone knows how to find character next to Y I’d appreciate

I get with event both backslash < and Ĺľ

< is bottom left next to Y

and Ĺľ is in middle back of Return

and they are both backslash

Hi,

I am having a slight problem with this code…
If I am holding down a direction key and then press shift it works but doesn’t detect that I have released shift until I have released the direction key too.
Are you using the DontTurnOffToggle somehow to fix this?

Cheers

Still doesn’t work on Unity 4.1.5, and the manual still has no warning :confused:

I reported a bug for shift keys in April this year, here is the thread :

http://forum.unity3d.com/threads/178942-Unity-3-5-7f6-dual-shift-key-bug

tested with “GetKey” , “GetKeyUp” and “GetKeyDown” - code included in thread - confirmed by another user - sample package sent with bug report - nothing happened

case number : 538538

I received a mail with a link to fogBugs to trace the bug report …

FogBugs link : https://fogbugz.unity3d.com/default…qm77l94pqksfhg

If you don’t want to go check the thread above then in a nut shell it describes the bug as been :

If you press and hold one shift key and then another shift key - if you release the second pressed shift key first, it will not fire and event. In fact it becomes completely unresponsive from that point onwards, so you can press and release it all you want thereafter, nothing will fire until you release the first pressed shift key.

This is not a keyboard hardware problem (eg non n-key rollover etc) as I have tested it in other software running on my machine and there is no problem in handling dual shift key events

Agh!!! SHIFT is such an important key in games! Give us bugs with… I don’t know… TAB! But not with SHIFT! :confused:

Still happening in Unity 4.2 :-p

I implemented my key up/down handling in separate methods. Then I poll for shift keys when Event.current.type == EventType.Repaint, keep track of current shift key state, and call my key handling methods when the state changes. Kludgy, but at least it lets me handle all my key events in one place.

I did the same, but it’s a pain in the ass and my code looks so unpolished like that :frowning:

I can confirm this happens in Unity 4.3.1f1 :frowning:

What I did to identify shift (and any other modifier key along the way, which was a nice bonus) was this:

if(Event.current.modifiers > 0)
  {
   if((Event.current.modifiers  EventModifiers.Shift) == EventModifiers.Shift)
   {
    Debug.Log("shift");
   }

   if((Event.current.modifiers  EventModifiers.Control) == EventModifiers.Control)
   {
    Debug.Log("control");
   }

//etc...
  }

It’s also possible to work with many simultaneous modifiers this way.
Hope this helps anyone who comes across!

Hello all,

It d be great if someone from Unity could comment on the status of this issue, if it is a feature or a bug, or maybe on how Shift-Key is supposed (not) to be used according to Unity-Philosophy.

Best regards,

Yup, would like an official response too, or even better a fix. The link to the bug says it was “moved”, and the other thread has no answer as this one.

Necro bump, but I have something to add.

In Unity 5.3.1 I’m trying to detect the exact moment a SHIFT key is pressed inside an EditorWindow (so not in runtime). Apparently, KeyDown events are not fired when SHIFT is pressed at all, while they work with ALT and CONTROL for example. Any news about this?

Still an issue in 5.2.4

Here is my workaround that seems to function well enough.

        if( e.shift )
        {
            KeyCode lShift = KeyCode.LeftShift;
            KeyCode rShift = KeyCode.RightShift;
            KeyCode thisShift = KeyCode.None;

            if( Input.GetKey(lShift) )
            {
                thisShift = lShift;
            }
            else if( Input.GetKey(rShift) )
            {
                thisShift = rShift;
            }

This actually only works in Editor, in a build, we don’t even get any events to check to see if shift is held down.