- Home /
New gui: How to disable keyboard input when user is typing?
How can I disable unrelated keyboard input when user is typing in an InputField?
What do you mean by "unrelated keyboard input" ? Like arrow keys ?
You could make a global GameController using the Singleton design pattern to access it from anywhere. In this object, define a boolean saying if the user is typing. Every object that would normally react to the keyboard input would check if the variable is set to true or not.
That's overly complex for just making character not move with WASD when he's typying in chat or something now is it? I need simple, easy to apply solution. Also I would have to scrap half of my code.
Answer by darkhog · Aug 15, 2015 at 05:59 PM
Okay, answering myself. Kinda hackish, but it works:
void Update () {
//switching between mouse modes
if ((Input.GetButtonUp("M"))){
GameObject go = EventSystem.current.currentSelectedGameObject;
InputField inputField = null; //creating dummy, null, InputField component
if (go!= null) {
inputField = go.GetComponent<InputField>(); //trying to get inputField component
}
//if inputField still equals null, it means user isn't in edit field
if (inputField==null) {Globals.lockmouse = !Globals.lockmouse;}
}
}
I'll try to refactor it later.
Answer by whaleinthesea · Aug 14, 2015 at 08:44 PM
With getnameoffocusedcontrol you can easily fix this. Add this script to your moving object:
if(GUI.GetNameOfFocusedControl() != "NameOfInputField"){
//your code to move the object
}
Darkhog is using the new GUI, not the legacy system. And this solution is pretty like the one I proposed, which doesn't fit his needs.
Your answer
Follow this Question
Related Questions
Hover Over Input Field Before Inputting? 2 Answers
Can I disable the use of Input.GetKey(KeyCode("any key")) while an InputField is in use? 2 Answers
Android Keyboard Stuck / Won't Hide? 1 Answer
Inputmode on 18:9 mobile device shows navigation bar 0 Answers
Holotoolkit on screen keyboard won't open,Hololens on-screen keyboard won't open 1 Answer