Activate right mouse button javascript

Hello everybody,

in my experiment, I would like to activate the right mouse button. Participants should be able to click with either the left or the right mouse button on a stimuli, which ends the routine. However, I am struggling with a solution.

I determined how to activate the “middle“ mouse button. But when I try to activate the right one, after a click a pop up appears which handles the stimuli (a polygon) like a picture (i.e. options like “download“, “store“, etc.)

Does anyone know a solution or a work around for this problem?

Thank you very much in advance.

@Lykanon, a workaround is to add the following to the “Begin Experiment” tab, which will disable the default right-mouse button behaviour of displaying a context menu:

preventClick = function (event) { event.preventDefault(); }
document.addEventListener("contextmenu", preventClick, event, false);

To restore the default behaviour of the right mouse button:

document.removeEventListener("contextmenu", preventClick, event, false);

I have only tested this using Chrome.

1 Like

Thank you very much @dvbridges! This solution works in Chrome, Firefox, Edge and Opera.

This is very helpful. Thanks.