onRightClick event handler??

Hi,
Is there such a thing?  If so, what's the correct syntax for LCick and RClick?
boatfulAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Michel PlungjanIT ExpertCommented:
<HTML>
<SCRIPT>
/* Cancel right mouse button
   (c) 1999 Michel Plungjan jav@scripting.demon.nl */

NN = (document.layers);
IE = (document.all);

if (NN) document.captureEvents(Event.MOUSEDOWN);

if (NN || IE) document.onmousedown=getMouse;

function getMouse(e) {
   if (NN && e.which==3) return false;
   if (IE && window.event.button==2) {
      alert('Mouse button cancelled');  // This is REQUIRED
      window.event.cancelBubble = true; // This aught to have been enough
      return false;
   }
   return true;
}
</SCRIPT>

</HTML>

The which==3 is right, which==1 is left, 2 is middle

IEs buttons are 1 left, 2 right, 4 middle

Michel
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
boatfulAuthor Commented:
Michel,
This is a cool script. I am trying to use it in physiotherapy, to quantify gait parameters of clients, left step==left click, etc.  

Somehow I need to blend this with a distinct end-of-test cue, such as <SPACEBAR> press. The script below does not seem to recognize ANY keystrokes in NN, and in IE only recognizes the spacebar if it follows a left click.  

The context-sensitive menus post-right click in IE are annoying, but do not seem to interfere with event sequencing.

I have increased points. Can you help me get the script below to recognize keystrokes in NN?

<html>
<head>
<script language='javascript'><!--Activate Cloaking
/* Cancel right mouse button
   (c) 1999 Michel Plungjan jav@scripting.demon.nl */

var NN = (document.layers);
var IE = (document.all);

if (NN) {
document.captureEvents(Event.MOUSEDOWN);
document.onmousedown=getMouseNN;
}

if (IE) document.onmousedown=getMouseIE;

function getMouseIE(e) {
   if (window.event.button==2) {
      addOne(new Date(),1,false);
      window.event.cancelBubble = true; // This ought to have been enough
      return false;
   }
   if (window.event.button==1) {
      addOne(new Date(),0,false);
      window.event.cancelBubble = true; // This ought to have been enough
      return false;
   }
   return true;
}

function getMouseNN(e) {
   if (e.which==3) {
      addOne(new Date(),1,false);
      return false;
   }
   if (e.which==1) {
      addOne(new Date(),0,false);
      return false;
   }
   return true;
}

function myKeyPress(e) {
    if (navigator.appName == "Netscape") {
        var charCode = e.which
    } else {
        var charCode = e.keyCode
    }
    if (charCode==115 || charCode==83 || charCode==32){
        alert("End of test");
        addOne(new Date(),nextFoot,true);
    }
}

//End Cloaking--></script>
</head>
<body onKeyDown="myKeyPress(event)">

</body>
</html>
0
Michel PlungjanIT ExpertCommented:
<html>
<head>
<script language='javascript'><!--Activate Cloaking
/* Cancel right mouse button
   (c) 1999 Michel Plungjan jav@scripting.demon.nl */

var NN = (document.layers);
var IE = (document.all);

if (NN) {
document.captureEvents(Event.MOUSEDOWN);
document.captureEvents(Event.KEYPRESS);
document.onmousedown=getMouseNN;
document.onkeydown=myKeyPress;
}

/* Variables and functions defined to stop errors due to missing functions */
n = 0;
nextFoot=0;
function addOne(d,nn,what) {
   n++;
   alert(n,d);
}

if (IE) document.onmousedown=getMouseIE;

function getMouseIE(e) {
   if (window.event.button==2) {
      addOne(new Date(),1,false);
      window.event.cancelBubble = true; // This ought to have been
enough
      return false;
   }
   if (window.event.button==1) {
      addOne(new Date(),0,false);
      window.event.cancelBubble = true; // This ought to have been
enough
      return false;
   }
   return true;
}

function getMouseNN(e) {
   if (e.which==3) {
      addOne(new Date(),1,false);
      return false;
   }
   if (e.which==1) {
      addOne(new Date(),0,false);
      return false;
   }
   return true;
}

function myKeyPress(e) {
    if (navigator.appName == "Netscape") {
        var charCode = e.which
    } else {
        var charCode = e.keyCode
    }
    if (charCode==115 || charCode==83 || charCode==32){
        alert("End of test");
        addOne(new Date(),nextFoot,true);
    }
}

//End Cloaking--></script>
</head>
<body onKeyDown="myKeyPress(event)">

</body>
</html>
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

boatfulAuthor Commented:
Michel,

This seems to work fine in NN.  

myKeyPress also works in IE following a left click (in other words,as long as the context-sensitive menu, or CSM, is NOT present). A workaround seems to be to hit "s" twice in rapid succession.  The first keystroke closes the CSM and the second launches myKeyPress.  This is ineffective if using the spacebar.

I have tried shifting focus to another frame after right-clicking in IE (to see if this automatically would nix the CSM) to no avail.  Any other ideas?

Tony
0
boatfulAuthor Commented:
Adjusted points to 200
0
Michel PlungjanIT ExpertCommented:
I am afraid not. It is a pain and I have not found any workaround for this weird behaviour.

Michel
0
boatfulAuthor Commented:
Thanks for all your help!
0
Michel PlungjanIT ExpertCommented:
Sorry that I could not be of more help with the last thing.
If I find a way I will let you know.

Michel
0
boatfulAuthor Commented:
One last thing...
Is the script at all compatible with IE4?

One last last thing...
I think line 12 needs to read:

document.captureEvents(Event.KEYDOWN);
0
Michel PlungjanIT ExpertCommented:
1. IE will only cancel right click if an alert is produced.
2. Netscape understands KEYPRESS, KEYDOWN and KEYUP.
You used onKeyDown in the body tag for IE so I am sorry that I read it wrong.

The spacebar gave me end of test in netscape 4.5 so the keypress also works

Michel
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.