+ Reply to Thread
Results 1 to 3 of 3

Thread: javascript hotkeys

  1. #1
    MasterMax1313's Avatar
    MasterMax1313 is offline x10Hosting Member MasterMax1313 is an unknown quantity at this point
    Join Date
    Oct 2007
    Posts
    84

    Question javascript hotkeys

    what i'm trying to do is capture certain types of key events with javascript. it's akin to using the text editor for the forums here, if you press ctrl+b then the text is bold, but the bookmarks don't come up.

    in my application i can get the event captured, the equivalent to making the text bold, but the bookmarks still come up.

    so basically i'm looking to make some hotkeys. any suggestions are appreciated

    Code:
    document.onkeydown = KeyCheck;//ctrlChk;
    document.onkeyup = ctrlChk;//KeyCheck;
    
    function ctrlChk(e)
    {
        var KeyID = (window.event) ? event.keyCode : e.keyCode;
        
        if(KeyID == 17)
        {
            ctrl = false;
        }
    }
    function KeyCheck(e)
    {
        var KeyID = (window.event) ? event.keyCode : e.keyCode;
        if(KeyID == 17)
            ctrl = true;
            if(window.event)
        {
            window.event.keyCode = 555;
            alert(event.keyCode);
        }
        else
        {
            window.e.keyCode = 555;
            alert(e.keyCode);
        }
        switch(KeyID)
        {
            /*case 17: // 'ctrl' - modifier key
                ctrl = true;
                break;*/
            case 19: //'pause' - pause/resume tourney
                tourneyGoing = !tourneyGoing;
                break;
            case 27: // 'esc' - remove '-'
                Escape();
                break;
            case 109: // '-' - wait for key for removal
                keypressMinus();
                break;
            default:
                break;
        }
        if(ctrl)
        {
            switch(KeyID)
            {
    --snip--
    If you found this helpful, don't be afraid to add to my rep
    ____________________________

    There are only 10 types of people in this world...

    Those who understand binary,
    And those who don't

  2. #2
    woiwky is offline x10 Lieutenant woiwky is an unknown quantity at this point
    Join Date
    Mar 2008
    Posts
    390

    Re: javascript hotkeys

    Why don't you use Event.ctrlKey to check the state of the control key when a key is pressed?

    But anyway, I believe that if you have the function return false, then it'll stop the browser hotkey from executing since onkeypress="return false;" seems to accomplish this.
    "But you have access to the greatest source of knowledge in the universe."
    "Well I do talk to myself sometimes, yes."

    "I'm back, and I'm bad! Obviously within certain, sensible, preset parameters"

  3. #3
    MasterMax1313's Avatar
    MasterMax1313 is offline x10Hosting Member MasterMax1313 is an unknown quantity at this point
    Join Date
    Oct 2007
    Posts
    84

    Re: javascript hotkeys

    thanks a ton, return false worked like a charm

    and i'll have to give the event.ctrlkey a shot, it may make my life a bit easier.

    edit:
    I switched to using event.ctrlkey, which is working much better than my previous method.
    Last edited by MasterMax1313; 04-29-2008 at 10:57 AM.
    If you found this helpful, don't be afraid to add to my rep
    ____________________________

    There are only 10 types of people in this world...

    Those who understand binary,
    And those who don't

+ Reply to Thread

Similar Threads

  1. javascript and external javascript files problem
    By delon in forum Programming Help
    Replies: 6
    Last Post: 04-27-2008, 12:41 AM
  2. JavaScript help!
    By disturbedart in forum Programming Help
    Replies: 5
    Last Post: 01-17-2008, 06:08 AM
  3. A question about javascript files
    By rlodge in forum Programming Help
    Replies: 6
    Last Post: 12-19-2007, 11:26 AM
  4. XML and Javascript
    By cuteboytm in forum Graphics & Webdesign
    Replies: 1
    Last Post: 09-21-2007, 10:00 AM
  5. Some nice-simple JavaScript effects !!
    By careerbridge in forum Scripts & 3rd Party Apps
    Replies: 1
    Last Post: 07-13-2006, 08:36 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
x10hosting free hosting for the masses
dedicated servers