none
How to disable keyboard shortcuts in IE7 / IE8

    Question

  • I'm doing some web development using ASP.NET 2.0. I'm using IE 7 and 8 as my browers and I'm trying to scan a complex barcode into the browser using a handheld scanner. The data that comes in via the scanner contains key sequences that translate to keyboard shortcuts so rather than pulling in all of my data correctly, the input of the data launches keyboard shortcuts to add the page to my favorites.

    So my question is whether there is a way to disable all keyboard shortcuts in IE when you open a specific .aspx page. I tried scanning using IE 6 and it worked fine, but not for 7 & 8.
    Wednesday, January 13, 2010 10:29 PM

Answers

  • In JavaScript you can attach and event listener that will handle all key presses and cancel them so they don't bubble up. Something like:

            window.onload = function() {
                window.document.body.onkeydown = function() {
                    var e = window.event; // this only works in IE other browsers pass in the arg rather than use window.event
    
                    if (e.ctrlKey) {
                        e.cancelBubble = true; // ie specific ff is preventDefault()
                        try {
                            e.keyCode = 0; // this is a hack to capture ctrl+f ctrl+p etc
                        }
                        catch (e) {
    
                        }
                        return false;
                    }
    
                    return true; // for keys that weren't shortcuts (e.g. no ctrl) then the event is bubbled
                }
            }
    


    Ideally you should use attachEvent to attach or addEventListener if you're using some cross-browser shim.
    Wednesday, January 13, 2010 10:42 PM

All replies

  • In JavaScript you can attach and event listener that will handle all key presses and cancel them so they don't bubble up. Something like:

            window.onload = function() {
                window.document.body.onkeydown = function() {
                    var e = window.event; // this only works in IE other browsers pass in the arg rather than use window.event
    
                    if (e.ctrlKey) {
                        e.cancelBubble = true; // ie specific ff is preventDefault()
                        try {
                            e.keyCode = 0; // this is a hack to capture ctrl+f ctrl+p etc
                        }
                        catch (e) {
    
                        }
                        return false;
                    }
    
                    return true; // for keys that weren't shortcuts (e.g. no ctrl) then the event is bubbled
                }
            }
    


    Ideally you should use attachEvent to attach or addEventListener if you're using some cross-browser shim.
    Wednesday, January 13, 2010 10:42 PM
  • Backspace means backspace vIP: e.cancelBubble = true; // ie specific ff is preventDefault() Prevent the backspace key bubbling up to the Body and firing the page back.
    Rob^_^
    Friday, February 18, 2011 7:51 PM
  • Hi,

    Can we do the same using batch file or vb script? So that i can deploy it in logon script. Any suggestions please

    Thanks,

    UdayaKumar S


    • Edited by Udayauk33 Tuesday, June 17, 2014 12:00 PM
    Tuesday, June 17, 2014 11:17 AM
  • Hi Udayauk33,

    sorry no... you need a COM browser helper object to inject the js scripts into each page or add the event handlers manually to your js sources.

    Regards.


    Rob^_^

    Wednesday, June 18, 2014 9:24 PM