var key = String.fromCharCode(inputmanager.getLastPressedKey());
var container = objects[0].getVariables();
var text = container.get("text").getAsString()+key;
objects[0].setVariableNumber(container.get("text"),text);
}[/code]
I guess I should use the name of the InputManager class in lowercase (inputmanager).
And to get the reference to object of object’s variable “text” I used container.get( “text”).
Finally, I managed to detect and store in a global variable keystrokes, to create a textbox.
Has been necessary to use two events, one to detect uppercase and lowercase letters, and another to detect special keys:
//To detect low and uppercase.
document.onkeypress=KeyPressed;
function KeyPressed(e)
{
var evtobj=window.event? event : e; //distinguish between IE's explicit event object (window.event) and Firefox's implicit.
var unicode=evtobj.charCode? evtobj.charCode : evtobj.keyCode;
if((unicode>=65 && unicode<=90)||(unicode>=97 && unicode<=122))
{
var actualkey=String.fromCharCode(unicode);
var container=runtimeScene.getGame().getVariables();
var text = container.get("gText").getAsString()+actualkey;
container.get("gText").setString(text);
}
}
//To detect special keys
document.addEventListener("keydown", KeyCheck); //or however you are calling your method
function KeyCheck(e)
{
var evtobj=window.event? event : e; //distinguish between IE's explicit event object (window.event) and Firefox's implicit.
var unicode=evtobj.charCode? evtobj.charCode : evtobj.keyCode;
switch(unicode)
{
case 8:
//alert("backspace");
var container=runtimeScene.getGame().getVariables();
var text = container.get("gText").getAsString();
if(text.length>0)
{
text = text.substring(0,text.length-1);
container.get("gText").setString(text);
}
break;
case 46:
//alert("delete");
break;
default:
break;
}
}