?
Solved

onRightClick event handler??

Posted on 1999-11-03
10
Medium Priority
?
4,299 Views
Last Modified: 2012-06-27
Hi,
Is there such a thing?  If so, what's the correct syntax for LCick and RClick?
0
Comment
Question by:boatful
  • 5
  • 5
10 Comments
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 800 total points
ID: 2179690
<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
 

Author Comment

by:boatful
ID: 2189421
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
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 2189915
<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
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 

Author Comment

by:boatful
ID: 2190720
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
 

Author Comment

by:boatful
ID: 2190722
Adjusted points to 200
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 2190736
I am afraid not. It is a pain and I have not found any workaround for this weird behaviour.

Michel
0
 

Author Comment

by:boatful
ID: 2190744
Thanks for all your help!
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 2190858
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
 

Author Comment

by:boatful
ID: 2190879
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
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 2190948
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

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

600 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question