#VRML V2.0 utf8
Viewpoint {
description "initial"
}
NavigationInfo {
type "EXAMINE"
}
# 板
Transform {
translation 0 0 -0.1
children [
Shape {
appearance Appearance {
material Material {
diffuseColor 0.0 0.5 0.2
}
}
geometry Box {
size 10 7 0.1
}
}
]
}
# 入力された文字
Transform {
translation -4.5 2.5 0
children [
Shape {
appearance Appearance {
material Material {
emissiveColor 1 1 0.999
}
}
geometry DEF Tx Text {
fontStyle FontStyle {
size 0.6
}
}
}
]
}
# キー入力センサーが追加される場所
DEF Gp Group {}
# キー入力処理スクリプト
DEF KeyInput-Sc Script {
eventIn SFInt32 set_keyCode
eventOut MFString string
field MFString Character [ "0123456789", "ABCDEFGHIJKLMNOPQRSTUVWXYZ", ":;,-./@", "[\\]^" ]
field SFInt32 line 0
url "javascript:
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);
}
}
"
}
ROUTE KeyInput-Sc.string TO Tx.string
# キー入力センサーノード追加スクリプト
DEF AddKeyboardSensor-Sc Script {
eventIn MFNode nodeAdded
eventOut MFNode children
eventOut MFString string
field MFString keySensorUrl "keysensor.wrl" # Contact用キー入力センサーノードが記述されたファイル
field SFNode thisNode USE AddKeyboardSensor-Sc # このスクリプトノード
field SFNode inputSc USE KeyInput-Sc # キー入力処理スクリプトノード
url "javascript:
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 + '.';
}
}
"
}
ROUTE AddKeyboardSensor-Sc.children TO Gp.children
ROUTE AddKeyboardSensor-Sc.string TO Tx.string