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 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?
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 …
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
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.
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.
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.
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?