Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 13 of 13
  1. #1
    New Coder
    Join Date
    Jun 2004
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question How can i raise ctrl keypress event on mouse click event

    Hello Friends,
    How can i call ctrl keypress event on mouse click event

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,068
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Do you mean something like this?
    Code:
    document.onclick=function(e){
      if (!e) e=event;
      if (e.ctrlKey){
        alert("CTRL key is pressed.");
      }
      else if (e.shiftKey){
        alert("SHIFT key is pressed.");
      }
      else if (e.altKey){
        alert("ALT key is pressed.");
      }
    }
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #3
    New Coder
    Join Date
    Jun 2004
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Actually i want to call CTRL key press event without pressing ctrl key..
    i have following code..

    <HTML>
    <HEAD>
    <script language="JavaScript">

    function test(e)
    {

    //Here I want to call ctrl key press event without pressing ctrl key
    var ctrlPressed = (window.Event) ? e.modifiers & Event.CTRL_MASK : e.ctrlKey;
    alert(ctrlPressed);


    }

    </script>
    </HEAD>
    <BODY >
    <form name=frmMain>
    <input type=button value='Click Me' name='btnClick' onclick='test(event)'>
    </form>
    </BODY>
    </HTML>


    and i want to call ctrl event automatically without pressing ctrl key....
    Last edited by kiransoanje; 07-05-2004 at 07:54 AM.

  • #4
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,068
    Thanks
    0
    Thanked 256 Times in 252 Posts
    I don't know what you exactly meant by "call ctrl key press event". Can you elaborate more? What's your ultimate reason for doing this?
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #5
    New Coder
    Join Date
    Jun 2004
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    when i logout from my application,if at that moment if yahoo companion popup is enable i m not able to login again from the same browser. For login i have to use another browser. In this case if i press ctrl key, at the time of logout it does not give above problem. So i want to give functionality such that when i click on logout button, it will fire ctrlkey press automatically without pressing it manually event.

    Problem does not occur if yahoo companion is disable.

  • #6
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,068
    Thanks
    0
    Thanked 256 Times in 252 Posts

    Solve the root of the problem

    What you need to solve is to find out why you can't login again from the same browser if that yahoo companion popup (what's that?) is enabled and find solution for it and not to find a solution for a "workaround".
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #7
    New Coder
    Join Date
    Jun 2004
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Though the root of cause is yahoo companion, i dont want to restrict user from utilization of yahoo companion. This is easily possible by pop up blocker or change in registry, but i think this is not the right solution.

  • #8
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You can only capture not force a key press.....

  • #9
    New to the CF scene
    Join Date
    Jul 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile Disabling a right-click for a PC AND ctrl-click for Mac

    I've got a client on a Mac who wants right-click disabled so people don't easily take her images. Disabling a right-click for a PC is easy, but on a Mac it's not really a right-click (even if there's a 2-button mouse), it's a ctrl-click. After many hours of trial and error, I have finally got the code that will work in both platforms and on several browsers. I thought I'd share it.
    (Yes, I understand that there really is no way to prevent an advanced web-user from downloading images and text, but the client really wants this to at least prevent some of the people)

    I have included the code below:
    This code goes between javascript tags in between the html head tags section

    <!--

    //Disable right mouse click Script
    var message="Function Disabled!";

    function clickIE4(){if (event.button==2){alert(message);return false;}}

    function clickNS4(e){if (document.layers||document.getElementById&&!document.all){if (e.which==2||e.which==3){alert(message);return false;}}}

    if (document.layers){document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickNS4;}
    else if (document.all&&!document.getElementById){document.onmousedown=clickIE4;}
    document.oncontextmenu=new Function("alert(message);return false")

    //Disable ctrl key
    if (document.all){
    document.onkeydown = function (){
    var key_ctrl = ctrlKey; // 17 is also ctrl Key

    if (key_ctrl==event.keyCode){
    alert(message);
    return false;
    }
    }
    }

    // -->
    Last edited by vapeterson; 07-22-2009 at 03:51 AM. Reason: html script

  • #10
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,079
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    vapeterson - why are you reviving this ancient thread?

    I expect your code is fine in IE4 or NS4. But times have moved on.

    Code:
    <script type = "text/javascript">
    
    document.onkeydown = function(ev) {	
    var key;
    ev = ev || event;
    key = ev.keyCode;
    alert ("Keycode = " + key);
    
    if (key == 17) {
    alert ("You pressed the CONTROL key");
    return false;
    }
    
    }
    </script>
    As you say, there is no way of preventing users from copying your images or text, as they have already been downloaded and are in the browser cache. A waste of time to try, in fact. Also, users (advanced or not) can simply disable Javascript. See the FAQs.

    And users will really love you if you disable the control key when they want to use
    CTRL+C (Copy)
    CTRL+X (Cut)
    CTRL+V (Paste)
    CTRL+Z (Undo)
    and so on.

    Suggest you forget the whole idea.
    Last edited by Philip M; 07-22-2009 at 08:45 AM.

  • #11
    Regular Coder
    Join Date
    Mar 2008
    Posts
    301
    Thanks
    2
    Thanked 30 Times in 30 Posts
    Quote Originally Posted by Philip M View Post
    As you say, there is no way of preventing users from copying your images or text, as they have already been downloaded and are in the browser cache. A waste of time to try, in fact. Also, users (advanced or not) can simply disable Javascript.
    Unless the script is what gets the text or images. I don't like the idea much. But some site owners are very jealous of their content.

    Check out the way Rhapsody.com protects its lyrics. It's pretty effective. Annoying - but effective.

  • #12
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,374
    Thanks
    11
    Thanked 592 Times in 572 Posts
    on FF/windows at least, you can drag an image from a page to the desktop...
    it's a little better to show the image as a css background property, rather than a tag.

    That way, most browsers won't even offer "Save Image As..." on right-click, javascript or no javascript.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.6, IE11:9.1, IE9:3.1, IE10:3.0, FF:17.2, CH:46, SF:11.4, NON-MOUSE:38%

  • #13
    Regular Coder
    Join Date
    Jun 2007
    Location
    USA
    Posts
    527
    Thanks
    26
    Thanked 74 Times in 72 Posts
    Print screen never fails.
    Trinithis


  •  

    LinkBacks (?)

    1. 02-24-2014, 01:49 AM

    Posting Permissions

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