Forum Discussion
Center Click Trigger
I would like to create a trigger that triggers on a center click (with a back-up trigger that I'm using now which is select then hit F9 if they don't have a mouse with a center clicking button). But I don't see center click as an option in the triggers.
Does anyone know if it's possible to do this?
- Nathan_HilliardCommunity Member
There is no built-in trigger for the middle mouse button. If you are willing to use some JavaScript, you can do something like the following.
This example watches for the click event on specific objects, and checks to see which button was used. If it was the middle button, it toggles a variable in Storyline. You can then use the "variable changes" trigger to do whatever you need to do. Just create a variable for each object you want to monitor (labeled "triggerMidClk_[object]" in the example).
Much of the JavaScript code is commented out, and is for disabling default button behavior in the browser. You may or may not need it. It is not needed for this example. This worked in Chrome and Firefox.
Note, if you enable the code inspector in Chrome or Firefox it takes over the middle button actions, so this example does not work while the inspector is open. You can use the built-in inspector in Storyline preview and it will still work.
Try it: https://360.articulate.com/review/content/a949846b-e785-44be-a8cf-82dbbc896509/review
- ThomasUmphresCommunity Member
Nathanial,
I got it with a javascript function that triggers when the objected is either selected or hovered over.
// Get the player object
var player = GetPlayer();
function simulateF9KeyPress() {
// Create a new KeyboardEvent
let event = new KeyboardEvent('keydown', {
key: 'F9',
code: 'F9',
keyCode: 120, // F9 key code
which: 120, // F9 key code
bubbles: true,
cancelable: true
});
// Dispatch the event on the document
document.dispatchEvent(event);
}
// Add event listener for middle mouse button click
document.addEventListener('mousedown', function(event) {
// Check if the middle mouse button (button code 1) was clicked
if (event.button === 1) {
simulateF9KeyPress();
}
});
// Optional: Prevent the default action of the middle mouse button click
document.addEventListener('click', function(event) {
if (event.button === 1) {
event.preventDefault();
}
});Thanks
- ThomasUmphresCommunity Member
For posterity's sake, that script didn't fully work, but this one did with a newly created variable called CenterClick:
// Get the player object
var player = GetPlayer();
function incrementCenterClick() {
// Get the Articulate Storyline player
var player = GetPlayer();
// Get the current value of the CenterClick variable from Storyline
var centerClickValue = player.GetVar("CenterClick");
// Increment the value by 1
centerClickValue += 1;
// Set the new value back to the CenterClick variable in Storyline
player.SetVar("CenterClick", centerClickValue);
// Optional: Log the new value to the console
console.log("CenterClick count is now:", centerClickValue);
}
// Add event listener for middle mouse button click
document.addEventListener('mousedown', function(event) {
// Check if the middle mouse button (button code 1) was clicked
if (event.button === 1) {
incrementCenterClick();
// Optional: Prevent the default action of the middle mouse button click
event.preventDefault();
}
});