2

Using Adobe InDesign's extendscript (javascript language), how can I add an onClick function for both left AND right click events?

Adding the left-click event is easy. How do I add the right-click event?

[post answer update (much thanks to Josh Voights for finding that)]

If anyone is interested, I wanted to use this in such a way to apply the handler to the button like this, which works perfectly:

whatbutton.addEventListener("click", function(p){
    if(!p.shiftKey){
        if (p.button ==2) {
            alert("right click");
        }else{
            alert("left click");
        }
    }else{
        if (p.button ==2) {
            alert("shift right click");
        }else{
            alert("shift left click");
        }
    }
bgmCoder
  • 6,205
  • 8
  • 58
  • 105

1 Answers1

2

Here's a code sample from kahrel.plus.com/indesign/scriptui.html that includes watching for a right click. Credit to @fabiantheblind in this stackoverflow answer.

var w =new Window ("dialog");
var b = w.add ("button", undefined, "Qwerty");

b.addEventListener("click", function (k){whatsup (k)});

function whatsup (p)
{
   if(p.button == 2){ $.writeln ("Right-button clicked.") }
   if(p.shiftKey){ $.writeln ("Shift key pressed.") }
   $.writeln ("X: "+ p.clientX);
   $.writeln ("Y: "+ p.clientY);
}
w.show ();
Community
  • 1
  • 1
Josh Voigts
  • 4,114
  • 1
  • 18
  • 43