• Function Key Event
  • //uncomment to prevent on startup
    //removeDefaultFunction();
    /** Prevents the default function such as the help pop-up **/
    function removeDefaultFunction()
    {
    window.onhelp = function () { return false; }
    }
    /** use keydown event and trap only the F-key,
    but not combinations with SHIFT/CTRL/ALT **/
    $(window).bind('keydown', function(e) {
    //This is the F1 key code, but NOT with SHIFT/CTRL/ALT
    var keyCode = e.keyCode || e.which;
    if((keyCode == 112 || e.key == 'F1') &&
    !(event.altKey ||event.ctrlKey || event.shiftKey || event.metaKey))
    {
    // prevent code starts here:
    removeDefaultFunction();
    e.cancelable = true;
    e.stopPropagation();
    e.preventDefault();
    e.returnValue = false;
    // Open help window here instead of alert
    alert('F1 Help key opened, ' + keyCode);
    }
    // Add other F-keys here:
    else if((keyCode == 113 || e.key == 'F2') &&
    !(event.altKey ||event.ctrlKey || event.shiftKey || event.metaKey))
    {
    // prevent code starts here:
    removeDefaultFunction();
    e.cancelable = true;
    e.stopPropagation();
    e.preventDefault();
    e.returnValue = false;
    // Do something else for F2
    alert('F2 key opened, ' + keyCode);
    }
    });

    by kevin 6 years ago 0 Comment

0 Comment

Leave Comment