| Register | FAQ | Calendar | Search | Today's Posts | Mark Forums Read |
|
#1
| |||
| |||
| Hi! I'm trying now to create the universal prototype for using as keyboard controller with both Cortona and Blaxxun/BS Contact without any special changes. It must automatically insert necessary node in dependency of Browser name. The method was quite obvious for me until I try to make dynamic routing of KbdSensor event using vrmlscript. Maybe someone could find my mistakes in the code: #VRML V2.0 utf8 DEF NI NavigationInfo {headlight FALSE type "NONE"} EXTERNPROTO DeviceSensor [ exposedField SFBool enabled exposedField SFString device exposedField SFString eventType exposedField SFNode event eventOut SFBool isActive ]["urn:inet:blaxxun.com:node eviceSensor","http ://www.blaxxun.com/vrml/protos/nodes.wrl#DeviceSensor","nodes.wrl#DeviceSensor"] DEF Clicker Script { eventOut SFBool turnLeft eventOut SFBool turnRight eventOut SFBool moveUp eventOut SFBool moveDown eventOut SFBool zoomIn eventOut SFBool zoomOut # for Cortona: eventIn SFInt32 c_keyDown eventIn SFInt32 c_keyUp # for Blaxxun: eventIn SFNode b_event url "javascript: function c_keyDown(val) {process(val,true);} function c_keyUp(val) {process(val,false);} function b_event(e,t) { if(e.type == 'keydown') process(e.keyCode,true); else if(e.type == 'keyup') process(e.keyCode,false); } function process(key,mode) { print('(test) key: '+key); // for test only if(key==65574||key==1004||key==65623||key==87) moveUp = mode; else if(key==65576||key==1005||key==65619||key==83) moveDown = mode; else if(key==65573||key==1006||key==65601||key==65) turnLeft = mode; else if(key==65575||key==1007||key==65604||key==68) turnRight = mode; else if(key==65643||key==65723||key==107||key==187) zoomIn = mode; else if(key==65745||key==65625||key==109||key==189) zoomOut = mode; } " } DEF Sensor Script { field SFNode Clicker USE Clicker field SFNode SensorNode NULL # for test only eventIn SFBool turnLeft eventIn SFBool turnRight eventIn SFBool moveUp eventIn SFBool moveDown eventIn SFBool zoomIn eventIn SFBool zoomOut # end of test url "javascript: // for test only function turnLeft(val) {print('(test ok): left');} function turnRight(val) {print('(test ok): right');} function moveUp(val) {print('(test ok): up');} function moveDown(val) {print('(test ok): down');} function zoomIn(val) {print('(test ok): zoomIn');} function zoomOut(val) {print('(test ok): zoomOut');} // end of test function initialize() { var bsens = 'DeviceSensor {device \"STANDARD\" eventType \"keydown keyup character\"}'; var csens = 'KbdSensor {isActive TRUE}'; br=Browser.getName(); br=br.toLowerCase(); if(br.indexOf('blaxxun')>=0||br.indexOf('contact') >=0) { SensorNode=Browser.createVrmlFromString(bsens)[0]; Browser.addRoute(SensorNode,'event',Clicker,'b_eve nt'); } else if(br.indexOf('cortona')>=0) { SensorNode=Browser.createVrmlFromString('KbdSensor {isActive TRUE}') [0]; print('(existance test) KbdSensor.isActive: '+SensorNode.isActive); // for test only Browser.addRoute(SensorNode,'keyDown',Clicker,'c_k eyDown'); Browser.addRoute(SensorNode,'keyUp',Clicker,'c_key Up'); } } " } # for test only ROUTE Clicker.turnLeft TO Sensor.turnLeft ROUTE Clicker.turnRight TO Sensor.turnRight ROUTE Clicker.moveUp TO Sensor.moveUp ROUTE Clicker.moveDown TO Sensor.moveDown ROUTE Clicker.zoomIn TO Sensor.zoomIn ROUTE Clicker.zoomOut TO Sensor.zoomOut # end of test |
|
#2
| |||
| |||
| Eureka! At last I made it work with both browsers! It use six keys in two variants: arrows up, down, left, right (W, S, A, D) and keys +/- (gray +/gray -). But you can add your own into function process(). P. S. This script by unknown author was useful for me. Thanks, man, whoever you are! http://img2.tapuz.co.il/CommunaFiles/13752093.txt Here is my result: PROTO Universal_Keyboard [ eventOut SFBool turnLeft eventOut SFBool turnRight eventOut SFBool moveUp eventOut SFBool moveDown eventOut SFBool zoomIn eventOut SFBool zoomOut ]{ DEF Container Group {children [ DEF Clicker Script { eventOut SFBool turnLeft IS turnLeft eventOut SFBool turnRight IS turnRight eventOut SFBool moveUp IS moveUp eventOut SFBool moveDown IS moveDown eventOut SFBool zoomIn IS zoomIn eventOut SFBool zoomOut IS zoomOut eventIn SFInt32 c_keyDown # for Cortona eventIn SFInt32 c_keyUp eventIn SFNode b_event # for Contact url "javascript: function c_keyDown(val) {process(val,true);} function c_keyUp(val) {process(val,false);} function b_event(e,t) { if(e.type == 'keydown') process(e.keyCode,true); else if(e.type == 'keyup') process(e.keyCode,false); } function process(key,mode) { if(key==65574||key==1004||key==65623||key==87) moveUp = mode; else if(key==65576||key==1005||key==65619||key==83) moveDown = mode; else if(key==65573||key==1006||key==65601||key==65) turnLeft = mode; else if(key==65575||key==1007||key==65604||key==68) turnRight = mode; else if(key==65643||key==65723||key==107||key==187) zoomIn = mode; else if(key==65645||key==65725||key==109||key==189) zoomOut = mode; } " } DEF SensorNode Group {} DEF Sensor Script { field SFNode Clicker USE Clicker field SFNode SensorNode USE SensorNode url "javascript: function initialize() { var bsens = 'EXTERNPROTO DeviceSensor ['+ ' exposedField SFBool enabled'+ ' exposedField SFString device'+ ' exposedField SFString eventType'+ ' exposedField SFNode event'+ ' eventOut SFBool isActive'+ '][\"urn:inet:blaxxun.com:node eviceSensor\",\"ht tp://www.blaxxun.com/vrml/protos/nodes.wrl#DeviceSensor\"] '+ 'DeviceSensor {device \"STANDARD\" eventType \"keydown keyup character\"}'; var csens = 'KbdSensor {isActive TRUE}'; br = Browser.getName().toLowerCase(); if(br.indexOf('blaxxun') >= 0 || br.indexOf('contact') >= 0) { SensorNode.addChildren = Browser.createVrmlFromString(bsens); Browser.addRoute(SensorNode.children[0], 'event', Clicker, 'b_event'); } else if(br.indexOf('cortona') >= 0) { sensor = Browser.createVrmlFromString(csens); SensorNode.addChildren = sensor; SensorNode.children[0] = sensor; Browser.addRoute(sensor[0], 'keyDown', Clicker, 'c_keyDown'); Browser.addRoute(sensor[0], 'keyUp', Clicker, 'c_keyUp'); } } " } ]} } |
|
#3
| |||
| |||
| On Mar 31, 10:32*pm, Lobotomy <mikhail.shevt...@gmail.com> wrote: > Eureka! At last I made it work with both browsers! It use six keys in > two variants: arrows up, down, left, right (W, S, A, D) and keys +/- > (gray +/gray -). But you can add your own into function process(). > > P. S. This script by unknown author was useful for me. Thanks, man, > whoever you are! http://img2.tapuz.co.il/CommunaFiles/13752093.txt I looked at the code you were having trouble with the other day, I couldn't find the exact fault with it though. Good to see you found a solution. With blaxxun being offline at the moment its hard to find this sort of example too. So thanks for posting the working version. Oh there is a simplification to your code: if (key>65000) key=(key-65600+64); then you can simplify the if statements to remove: if (....key==65xxx |
|
#4
| |||
| |||
| On 1 ÁÐÒ, 09:38, fabricator <fabricatorgene...@yahoo.com> wrote: > On Mar 31, 10:32špm, Lobotomy <mikhail.shevt...@gmail.com> wrote: > > > Eureka! At last I made it work with both browsers! It use six keys in > > two variants: arrows up, down, left, right (W, S, A, D) and keys +/- > > (gray +/gray -). But you can add your own into function process(). > > > P. S. This script by unknown author was useful for me. Thanks, man, > > whoever you are!http://img2.tapuz.co.il/CommunaFiles/13752093.txt > > I looked at the code you were having trouble with the other day, I > couldn't find the exact fault with it though. > Good to see you found a solution. > > With blaxxun being offline at the moment its hard to find this sort of > example too. So thanks for posting the working version. > > Oh there is a simplification to your code: > if (key>65000) key=(key-65600+64); > > then you can simplify the if statements to remove: > if (....key==65xxx The problem was about working code in Cortona but in Blaxxun it was doing well. And the only way to check it is to press keys with that black-screen-scene loaded and watch print() messages. So Cortona didn't response. Thanks, I thought about making this simplification but had to refuse this idea after realizing that scancodes of unsymbolic keys are different for Cortona and Blaxxun. I use arrow keys and plus/minus in my project, so if I minus 65536 (also 2 bytes or 0x10000) from the number they would mess up and cause risk of mistaken recognition. |
![]() |
| Thread Tools | |
| Display Modes | |
In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.