- Home /
How to slow down GUI
I have a date of birth textField that is working beautifully until I build it. When built the input is super sensitive. I select the field, hit a number key and WHAM ... that number takes the next 3 places in the date string before it stops entering and politely waits for another number. On entering another number WHAM .. another three entries of that number. Obviously I am not going to ever get a valid date this way.
Any suggestions as to why this is? And more importantly how to get it under control? This works exactly as expected in the editor. It only gets crazy on build. Arrrrghhhhhhh .....
I put in a 5000 increment loop to print something. That slowed it down but just limited the display to taking up one extra character. Better but not a solution.
Please post your code as to how you're taking input and what you're doing with it.
$$anonymous$$y guess is 'it's' listening out for a keydown event, not a keydown event followed by a keyup event.
Thanks for looking at this ... I am going nuts .... I have taken out all the prints and commented stuff to try to clear it out, hope it is legible.
dosString = GUI.TextField (new Rect(25, 115, 100, 24), dosString, 10, textFieldStyle); // $$anonymous$$$$anonymous$$/dd/yyyy
chr = Event.current.character;
// Establish control of cursor with the following line TextEditor editor = (TextEditor)GUIUtility.GetStateObject(typeof(TextEditor), GUIUtility.keyboardControl);
if(chr == '0' || chr == '1' || chr == '2' || chr == '3' || chr == '4' || chr == '5' || chr == '6' || chr == '7' || chr == '8' || chr == '9'){
if (charCount>9) charCount = 0; // reset count increment to zero
if(charCount == 2 || charCount == 5){ // force set of the slash between $$anonymous$$,d,y
dosStringArray[charCount] = "/";
charCount++;
}
dosStringArray[charCount] = chr.ToString();
charCount++;
editor.selectPos = charCount-1; // set the cursor position
editor.pos = charCount-1; // set the cursor position
chr = 'k'; // trying to prevent focus from dropping back in the num test above
}
else{ dosString = ""; for(int x=0; x
chr = 'k'; // trying to prevent focus from dropping back in the num test above
Event.current.character = 'k'; // SET THIS TO PREVENT FOCUS DROPPING THROUGH NU$$anonymous$$BER TEST ABOVE
Answer by diggerjohn · Apr 13, 2014 at 11:00 PM
The solution was
if(Event.current.type.ToString() == "used")
This only passes once per event. This is the best way I found to stop the focus from rolling through the standard OnGUI 2 cycles per frame.
Answer by ivomarel · Apr 08, 2014 at 06:55 PM
You should use Input.GetKeyDown instead of Input.GetKey .
I have tried ...
if(Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.Alpha1)|| Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.Space)){
gottaNumberDOS = true;
print ("gottaNumberDOS = " + gottaNumberDOS);
}
As a test within OnGUI but it does not seem to be seen by GUI. It compiles alright but I get no response from Input.Get$$anonymous$$eyDown
Your answer
Follow this Question
Related Questions
Get key state while textfield has focus? 0 Answers
Input not registering while TextField is selected 3 Answers
TextField, Event.current, Input.GetKey, and GUI.FocusControl locking 1 Answer
Distribute terrain in zones 3 Answers
Backspace in limited length textfield causes ArgumentOutOfRangeException 1 Answer