Page 1 of 2 12 LastLast
Results 1 to 10 of 16

Thread: Override default key ...

  1. #1
    Join Date
    Aug 2005
    Posts
    971
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Override default key ...

    Is there any way to override default key events like Ctrl+A or Ctrl+P like in this website: http://www.jgraph.com/mxgraph/ (hit ctrl+A to see the event)?? It does not select the text in a normal way(like when you select a text the background turns bluish). If anyone know how this can be done then I would be appreciated with your help.
    Last edited by shachi; 06-18-2006 at 10:16 AM.

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    If you return false from an onkeypress event, the normal action will not be performed.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Aug 2005
    Posts
    971
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Sorry but I didn't get it. Ctrl+A is not a default keypress and how do I return a keypress false?? Please can you make this clear for me??

  4. #4
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    1. This will fail on macs.
    2. While Twey did give you a way... (see below for an example), the main point here is that you seem to be trying to stop people from saving your content, etc. If this is the case GIVE UP, because it simply cannot be done and goes against all the standards of the web. Not only is it not possible, but if you try, you'll just end up with a heavily coded page that will confuse your normal visitors.


    As for the return false thing... if you didn't want a link to work, you could try something like this:
    <a href="whatever.htm" onClick="return false;">
    And it would do nothing.
    *I think this is the right code, but might be slightly off.
    Basically.... just use "return false;" in place of where javascript to be executed would go, and this will instead make it not execute.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  5. #5
    Join Date
    Aug 2005
    Posts
    971
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by djr33
    2. While Twey did give you a way... (see below for an example), the main point here is that you seem to be trying to stop people from saving your content, etc. If this is the case GIVE UP, because it simply cannot be done and goes against all the standards of the web. Not only is it not possible, but if you try, you'll just end up with a heavily coded page that will confuse your normal visitors.
    Actually I am not doing this to stop people from saving my content but I had made a script to increase and decrease textboxes(just like this one) and I wanted it to increase when the user hits Ctrl+I and decrease when he hits Ctrl+D but in firefox and some other browsers this didn't seem to work as those events are already registered for Page Info and Bookmarks so I wanted to override those events. But I don't have a clue how I can do it so I came across that site and knew that it was what I wanted and I seeked for your help.

    But still I don't have any idea how it can be done. Thanks anyways.

  6. #6
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Ah, ok. Then the issue here is that you might not have complete compatibility, and you wouldn't want someone with a weird browser bookmarking your site instead of changing text size, or whatever.

    I'd suggest using Alt+Letter instead. That's the standard way of doing web-based user input from the keyboard.

    It'll save you a lot of time as well.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  7. #7
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  8. #8
    Join Date
    Aug 2005
    Posts
    971
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks Twey, drj33. Let me see the link Twey gave me and if I still have problems then I am afraid I need to bother again.

    Unlucky me!

  9. #9
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Sure.

    Just remember the alt way will be easier, if not as automatic for the user.

    Even this forum, when making a post (in the editing mode, not the quick reply mode) has Alt+S=post, etc.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  10. #10
    Join Date
    Aug 2005
    Posts
    971
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Yes I can use the Alt key using the accesskey simply and it would also be easier for me but the one whose website I am making says it needs to be Ctrl and I am tired of convincing him about it.

    By the way Twey I read that article and I it doesn't seem to be working.
    Here's the code.
    Code:
    <script type="text/javascript">
    
    document.onkeydown = keypress;       
    
    
    function keypress(e){
    
    var key_s = (window.event) ? event.keyCode : e.keyCode;
    if(key_s == 17 && 65){
    alert("This event is supposed to show an alert AND not select the text");
    return false;
    }
    }
    </script>
    <body>
    bla lba blalklddjkfjkdfsjkldfsjkldfsjkldfsjl<br>
    bla lba blalklddjkfjkdfsjkldfsjkldfsjkldfsjl<br>
    bla lba blalklddjkfjkdfsjkldfsjkldfsjkldfsjl<br>
    bla lba blalklddjkfjkdfsjkldfsjkldfsjkldfsjl<br>
    bla lba blalklddjkfjkdfsjkldfsjkldfsjkldfsjl<br>
    bla lba blalklddjkfjkdfsjkldfsjkldfsjkldfsjl<br>
    bla lba blalklddjkfjkdfsjkldfsjkldfsjkldfsjl<br>
    bla lba blalklddjkfjkdfsjkldfsjkldfsjkldfsjl<br>
    bla lba blalklddjkfjkdfsjkldfsjkldfsjkldfsjl<br>
    bla lba blalklddjkfjkdfsjkldfsjkldfsjkldfsjl<br>
    bla lba blalklddjkfjkdfsjkldfsjkldfsjkldfsjl<br>
    bla lba blalklddjkfjkdfsjkldfsjkldfsjkldfsjl<br>
    bla lba blalklddjkfjkdfsjkldfsjkldfsjkldfsjl<br>
    bla lba blalklddjkfjkdfsjkldfsjkldfsjkldfsjl<br>
    bla lba blalklddjkfjkdfsjkldfsjkldfsjkldfsjl<br>
    bla lba blalklddjkfjkdfsjkldfsjkldfsjkldfsjl<br>
    bla lba blalklddjkfjkdfsjkldfsjkldfsjkldfsjl<br>
    bla lba blalklddjkfjkdfsjkldfsjkldfsjkldfsjl<br>
    bla lba blalklddjkfjkdfsjkldfsjkldfsjkldfsjl<br>
    bla lba blalklddjkfjkdfsjkldfsjkldfsjkldfsjl<br>
    bla lba blalklddjkfjkdfsjkldfsjkldfsjkldfsjl<br>
    bla lba blalklddjkfjkdfsjkldfsjkldfsjkldfsjl<br>
    bla lba blalklddjkfjkdfsjkldfsjkldfsjkldfsjl<br>
    bla lba blalklddjkfjkdfsjkldfsjkldfsjkldfsjl<br>
    bla lba blalklddjkfjkdfsjkldfsjkldfsjkldfsjl<br>
    bla lba blalklddjkfjkdfsjkldfsjkldfsjkldfsjl<br>
    bla lba blalklddjkfjkdfsjkldfsjkldfsjkldfsjl<br>
    bla lba blalklddjkfjkdfsjkldfsjkldfsjkldfsjl<br>
    bla lba blalklddjkfjkdfsjkldfsjkldfsjkldfsjl<br>
    bla lba blalklddjkfjkdfsjkldfsjkldfsjkldfsjl<br>
    bla lba blalklddjkfjkdfsjkldfsjkldfsjkldfsjl<br>
    bla lba blalklddjkfjkdfsjkldfsjkldfsjkldfsjl<br>
    bla lba blalklddjkfjkdfsjkldfsjkldfsjkldfsjl<br>
    </body>
    There are two problems in this. First that the alert comes up as soon as I press Ctrl and another is that the text gets selected.

    I'd be very grateful if anyone can tell me the problem and If nothing works then I must go to the accesskey method.

    Thanks everybody.

Bookmarks

Posting Permissions

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