Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2006
    Posts
    4

    Unanswered: detect mouse events with Ctrl + N?

    I have a smal problem :
    How do I detect mouse events with Ctrl + N?
    this is to open the window in a new window

    Exp:

    <script language="JavaScript">
    <!--
    function mouseDown(e) {
    var ctrlPressed=0;
    var altPressed=0;
    var shiftPressed=0;
    if (parseInt(navigator.appVersion)>3) {
    if (navigator.appName=="Netscape") {
    var mString =(e.modifiers+32).toString(2).substring(3,6);
    shiftPressed=(mString.charAt(0)=="1");
    ctrlPressed =(mString.charAt(1)=="1");
    altPressed =(mString.charAt(2)=="1");
    self.status="modifiers="+e.modifiers+" ("+mString+")"
    }
    else {
    shiftPressed=event.shiftKey;
    altPressed =event.altKey;
    ctrlPressed =event.ctrlKey;
    self.status=""
    + "shiftKey="+event.shiftKey
    +", altKey=" +event.altKey
    +", ctrlKey=" +event.ctrlKey
    }
    if (shiftPressed || altPressed || ctrlPressed)
    alert ("Mouse clicked with the following keys:\n"
    + (shiftPressed ? "Shift ":"")
    + (altPressed ? "Alt " :"")
    + (ctrlPressed ? "Ctrl " :"")
    )
    }
    return true;
    }
    if (parseInt(navigator.appVersion)>3) {
    document.onmousedown = mouseDown;
    if (navigator.appName=="Netscape")
    document.captureEvents(Event.MOUSEDOWN);
    }
    //-->
    </script>

  2. #2
    Join Date
    Jan 2006
    Posts
    4
    Exp2:
    Alt only modifiers=1 (001)
    Ctrl only modifiers=2 (010)
    Ctrl+Alt modifiers=3 (011)
    Shift only modifiers=4 (100)
    Shift+Alt modifiers=5 (101)
    Shift+Ctrl modifiers=6 (110)
    Shift+Alt+Ctrl modifiers=7 (111)
    None of these keys modifiers=0 (000)

    But
    Ctrl+N modifiers=??? (?????????)

    please help me

  3. #3
    Join Date
    Apr 2005
    Location
    Baltimore, MD
    Posts
    297
    I don't think the 'n' key is classified as a modifier when it is held in conjunction with ctrl. Try registering another function to the keydown event to flag n as being down. And another on key up / key release. Don't know exact syntax right now, but something like.

    Code:
    document.onkeydown = doKeyPress;
    
    //global variable
    var ndown = false;
    
    function doKeyPress()
    {
       if (keyChar == 'n') {
          ndown = true;
       }
    }
    (P.S. - javascript is not JAVA )

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •