hi all
i’m trying to receive keyboard input text without defining a GUI.TextField but the input stream only provides unique keys pressed.
I’m using Input.inputString to access keyboard input.
what am i doing wrong?
thanks again
Elan.
hi all
i’m trying to receive keyboard input text without defining a GUI.TextField but the input stream only provides unique keys pressed.
I’m using Input.inputString to access keyboard input.
what am i doing wrong?
thanks again
Elan.
What do you mean by "only provides unique keys"?
The documentation states that Input.inputString "returns the keyboard input entered this frame."
In other words, it's very unlikely that it will ever contain more than one character at a time (unless somebody is typing VERY fast or your game is running VERY slow).
If you're trying to gather the user's Input over time, you'll have to collect the values of Input.inputString over time.
I've never used Input.inputString, but I would try something like this (untested):
var userInput : String = "";
var labelRect : Rect = Rect(200, 200, 400, 100);
var clearRect : Rect = Rect(200, 300, 100, 40);
function Update ()
{
if ( Input.inputString ) {
userInput += Input.inputString;
}
}
function OnGUI ()
{
GUI.Label(labelRect, "userInput: " + userInput);
if ( GUI.Button(clearRect, "Reset") ) {
userInput = "";
}
}
If you're trying to test for the user holding multiple keys down at the same time, you should look into the Input.GetKey function.
Hi,
Thanks for the quick response.
ur code works. however, if i was to change ur updae function from
function Update ()
{
if ( Input.inputString ) {
userInput += Input.inputString;
}
}
to
function Update ()
{
if ( Input.inputString ) {
print (“input=” + Input.inputString;
}
}
it will only print unique char values.
anyway, ur code did provide me with an idea how to get around collecting chars without showing them
Thanks again,
Elan