- Home /
How to change anyKey in to anyKeyDown? with proper inputString.
this is the problem I'm heaving:
IF I press
a
I get Debug:
false: Length: 0
For code:
void Update(){
if (Input.anyKeyDown){
Debug.Log("false: " + Input.inputString + " Length: " + Input.inputString.Length);
if (Input.inputString.Length == 1){
Debug.Log("true: " + Input.inputString);
}
}
}
IF I press
a
I get Debug:
false: a Length: 1
true: a
For Code:
void Update(){
if (Input.anyKey){
Debug.Log("false: " + Input.inputString + " Length: " + Input.inputString.Length);
if (Input.inputString.Length == 1){
Debug.Log("true: " + Input.inputString);
}
}
}
This works perfectly EXCEPT I want to fetch only key downs, .... How should I do that?
In the last code I also GET
1X false: a Length: 1
1X true: a
2X false: Length: 0
Hmmm, yep the input string will be updated on 'Up' not on 'Down', what are you after doing?
I'm working on GUI3D
everything already works perfectly even "Layout" but this gives me huge problems, right now.
yes I really need down
think how strange it would look like if you pressing something would yield after up and not down.
if it would be for me I could go with up but it's not for me, ...
AND this is in the Update
EVEN $$anonymous$$ORE!!!
there's no any$$anonymous$$eyUp in Input. ...
This doesn't appear to work with 'system keys', things like delete and ctrl and such but does seem to work with backspace and letters and quite a few others:
var onDown : boolean = false;
var inputString : String;
function Update () {
if (Input.any$$anonymous$$eyDown){
onDown = true;
}
if(onDown && Input.inputString.Length != 0){
inputString = Input.inputString;
onDown = false;
}
}
It does seem very strange that its not possible to access Input.inputString from the any$$anonymous$$eyDown input.
Scribe
Answer by sdgd · Feb 13, 2014 at 07:00 AM
Finally after trying and trying, ... I finally figured out how should I do it, ...
thanks to @whydoidoit and @Scribe
I learned the complete machanics behind it, ... so what I did is:
bool OnDown = false;
void Update(){
if (OnDown){
// my code
OnDown = false;
}
if (Input.anyKeyDown){
onDown = true;
}
}
so it actually has to pass 1 FRAME in order to get the character in, ...
and no @whydoidoit I couldn't do only with
Input.inpusString > 0
because there was lots of inputs that take 1 length like backslash, enter/return, ... Witch are mostly collected before, ... and lots of them that take 0 like delete and even more of them, ....