Controller button trigger the function in another js file


#1

Hi

This is probably really basic, but I am trying to use the left menu button of the Vive controller to open the Marketplace.
Which I am expecting that instead of uses the mouse to click the “EXAMPLES” icon, I could simply press the left menu button to open the window, and close it by click it again.
I had found that the left menu button is mapped as Standard.LeftSecondaryThumb in Vive.json
{ “from”: “Vive.LeftApplicationMenu”, “to”: “Standard.LeftSecondaryThumb” },
And I created a new js file which includes the following codes copied from the docs
// The name of the new mapping
var MAPPING_NAME = “com.highfidelity.controllers.example.triggerExample”;

// Create a new mapping object
var mapping = Controller.newMapping(MAPPING_NAME);

// Add a route to the mapping object
 mapping.from(Controller.Standard.RT).to(function (value) {
     print("Right trigger is " + value);
 });

//Enable the new mapping
 Controller.enableMapping(MAPPING_NAME);

// Disable the new mapping when the script ends
 Script.scriptEnding.connect(function () {
     Controller.disableMapping(MAPPING_NAME);
});

The code works, however, I cannot figure out how to map the key.
I tried to include examples.js and use mapping.from(Controller.Standard.RB).to(examples.toggleExamples());

Script.include([
    "examples.js",
]);

// The name of the new mapping
var MAPPING_NAME = "com.highfidelity.controllers.example.triggerExample";

// Create a new mapping object
var mapping = Controller.newMapping(MAPPING_NAME);

// Add a route to the mapping object
 mapping.from(Controller.Standard.LeftSecondaryThumb).to(examples.toggleExamples());

//Enable the new mapping
 Controller.enableMapping(MAPPING_NAME);

// Disable the new mapping when the script ends
 Script.scriptEnding.connect(function () {
     Controller.disableMapping(MAPPING_NAME);
});

But it did not work.
I also tried without including examples.js or just use toggleExamples();

Could someone point me to some document or kindly tell me how to do it?

Thanks.


#2

Does it work to just include examples.js and call examples.toggleExamples?
If you’re still having problems I can try myself later, I have some experience with controller mapping, the mapping part looks correct.