typewriter_0_00.x3d source
<?xml version="1.0" encoding="UTF-8"?>
<X3D>
<Scene>
<Viewpoint description='initial'/>

<NavigationInfo
type='
"EXAMINE"'
/>

<!-- board -->
<Transform translation='0 0 -0.1'>
<Shape>
<Appearance>
<Material diffuseColor='0 0.5 0.2'/>
</Appearance>
<Box size='10 7 0.1'/>
</Shape>
</Transform>

<!-- Text -->
<Transform translation='-4.5 2.5 0'>
<Shape>
<Appearance>
<Material emissiveColor='1 1 0.999'/>
</Appearance>
<Text DEF='Tx'>
<FontStyle size='0.6'/>
</Text>
</Shape>
</Transform>

<!-- Place where the Key sensor is set -->
<Group DEF='Gp'>
</Group>

<Script DEF='KeyInput-Sc'>
<field accessType='inputOnly' type='SFInt32' name='set_keyCode'/>
<field accessType='outputOnly' type='MFString' name='string'/>
<field accessType='initializeOnly' type='MFString' name='Character' value='"0123456789" "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ":;,-./@" "[\\]^"'/>
<field accessType='initializeOnly' type='SFInt32' name='line' value='0'/>
<![CDATA[ecmascript:

function initialize () {
string[0] = '';
}

function set_keyCode (code) {

code = code % 65536;

if ( code == 13 ) {

// Enter key
string[++line] = '';
}
else if ( code == 8 ) {

// Back space Key
if ( string[line].length == 0 && line > 0) line--;
string[line] = string[line].substring ( 0, string[line].length-1 );
}
else if ( code == 32 ) {

// Space Key
string[line] += ' ';
}
else if ( code >= 48 && code <=57 ) {

// 0-9 Key
string[line] += Character[0].charAt(code-48);
}
else if ( code >= 65 && code <=90 ) {

// A-Z Key
string[line] += Character[1].charAt(code-65);
}
else if ( code >= 186 && code <=192 ) {

// :;,-./@ Key
string[line] += Character[2].charAt(code-186);

}
else if ( code >= 219 && code <=222 ) {

// [\]^ Key
string[line] += Character[3].charAt(code-219);
}

}
]]>
</Script>
<ROUTE fromNode='KeyInput-Sc' fromField='string' toNode='Tx' toField='string'/>

<Script DEF='AddKeyboardSensor-Sc'>
<field accessType='inputOnly' type='MFNode' name='nodeAdded'/>
<field accessType='outputOnly' type='MFNode' name='children'/>
<field accessType='outputOnly' type='MFString' name='string'/>
<field accessType='initializeOnly' type='MFString' name='keySensorUrl' value='"keysensor_00.x3d"'/>
<field accessType='initializeOnly' type='SFNode' name='thisNode'>
<Script USE='AddKeyboardSensor-Sc'/>
</field>
<field accessType='initializeOnly' type='SFNode' name='inputSc'>
<Script USE='KeyInput-Sc'/>
</field>
<![CDATA[ecmascript:

function nodeAdded (nodes) {

children[0] = nodes[0];
Browser.addRoute( nodes[0], 'keyPress', inputSc, 'set_keyCode' );

}

function initialize() {

var brwName = Browser.getName();

if ( brwName == 'Cortona VRML Client' ) {

var keySensorNode = new SFNode ( 'KbdSensor { isActive TRUE }' );
children[0] = keySensorNode;
Browser.addRoute( keySensorNode, 'keyDown', inputSc, 'set_keyCode' );

}
else if ( brwName == 'blaxxunCC3D' ) {

Browser.createVrmlFromURL ( keySensorUrl, thisNode, 'nodeAdded' );

}
else {

string[0] = 'Sorry...';
string[1] = 'This does not operate in ' + brwName + '.';

}
}
]]>
</Script>
<ROUTE fromNode='AddKeyboardSensor-Sc' fromField='children' toNode='Gp' toField='children'/>
<ROUTE fromNode='AddKeyboardSensor-Sc' fromField='string' toNode='Tx' toField='string'/>
</Scene>
</X3D>