Link to home
Start Free TrialLog in
Avatar of boatful
boatful

asked on

onRightClick event handler??

Hi,
Is there such a thing?  If so, what's the correct syntax for LCick and RClick?
ASKER CERTIFIED SOLUTION
Avatar of Michel Plungjan
Michel Plungjan
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of boatful
boatful

ASKER

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>
<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>
Avatar of boatful

ASKER

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
Avatar of boatful

ASKER

Adjusted points to 200
I am afraid not. It is a pain and I have not found any workaround for this weird behaviour.

Michel
Avatar of boatful

ASKER

Thanks for all your help!
Sorry that I could not be of more help with the last thing.
If I find a way I will let you know.

Michel
Avatar of boatful

ASKER

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);
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