Because I could not trigger an onClick event with 'gamepadbuttondown:8' from the gamepad controller,
I have the built a work-around that should be easy to implement in the next version of gamepad-controls.
Using a simple lightswitch as an example: https://jsfiddle.net/RonK/vm81ddn7/8/
The onClick event in the is set to onClick="SetSubjectOfFocus('lightswitch')";
This way clicking on the switch object with a normal mouse click sets the object to be effected,
And a fusion-cursor event also sets it, without it being triggered.
Event-listeners are added:
Classroom.addEventListener('gamepadbuttondown:8', function () {
ClickFunctionList('gp8');
});
Classroom.addEventListener('gamepadbuttondown:0', function () {
ClickFunctionList('gp0');
});
Classroom.addEventListener('mouseup', function () {
ClickFunctionList('msu');
});
Classroom.addEventListener('touchend', function () {
ClickFunctionList('tche');
});
Classroom.addEventListener('click', function () {
ClickFunctionList('clk');
});
Each event-listener passes on a nametag for itself in the arguments so that the actual triggering events
can have separate functions enabled in the ClickFunctionList().
//if gamepad is present (GPP=true or false)
function ClickFunctionList(TriggeredBy){
if(SubjectOfFocus=='light switch' && TriggeredBy=='gp0'){LightToggle();}
if(SubjectOfFocus=='light switch' && TriggeredBy=='clk' && GPP==false){LightToggle();}
if(SubjectOfFocus=='light switch' && TriggeredBy=='tche'){LightToggle();}
if(SubjectOfFocus=='light switch' && TriggeredBy=='gp8'){SearchSay(LsnVoc,0,'light switch');}
}
Clicking with a mouse works, and touch events on a phone or tablet work.
Clicking with a gamecontroler works.
Adding var GPP will allow you to get different results:
GPP==false: lets cursor-fusion click and trigger the lightswitch if wearing phone in a HMD.
GPP==true: keeps cursor-fusion from activating switch at a glance, requiring a controler-click.
--
If implemented as part of "gamepad-controls", it could absorb the ClickFunctionList invisable to the user.
It could either use the "this" feature in javascript to identify each event (but would require raycaster?)
Or, at runtime the controller.js could use QuerySelector to search the objects in the scene for:
"OnButton1" or similar markers, identifying:
and setting the: if(SubjectOfFocus=='light switch' && TriggeredBy=='gp1'){LightToggle();}
all by itself.