ctrl-P

0
0

Hello all,

I have an app that needs to catch ctrl-P, page-up, page-down, and various other keys.  Of course, most browsers pop up a print dialog when you hit ctrl-P, and other things when you hit the other keys.  I tried adding some javascript code like this to my Default.html

       document.onkeydown = function(e)
        {
            e = e || window.event;
            var c = e.which || e.keyCode;
            c = String.fromCharCode(c).toLowerCase();
            if (
                // ctrl-p/P
                (e.ctrlKey && (c == 80 || c == 112)) ||
                // f-keys
                (c >= 112 && c <= 123) ||
                // insert
                (c == 45) ||
                // up, down, left, right
                (c >= 37 && c <=40) ||
                // page up/down
                (c == 33 || c == 34) ||
                // escape
                (c == 27) ||
                // enter
                (c == 10 || c == 12)
                )
            {
                e.preventDefault();
                return false;
            }
        }

Which originally worked, but no longer works.  Either a recent Mozilla or WiseJ update broke it, or maybe there’s a bug that I can’t see.

Has anyone else tried doing this?

Am I even on the right track, or is there a different, recommended way to do this?

 

Thanks,

 

David Muse

david.muse@firstworks.com

  • You must to post comments
0
0

Ok, I got it to work, more or less.  It looks like I have a problem with focus now, but I should be able to resolve that.

Thanks!

  • You must to post comments
0
0

I just tried with this.Accelerators = new Keys[] { Keys.Control | Keys.P }; and I can catch Ctrl-P. Wisej will automatically block the browser from processing the accelerator.

The issue maybe that  you are registering the accelerator on a Form and then pressing Ctrl-P when the form is not active or doesn’t contain the focus. Wisej will process the accelerator only if the keydown is generated by a child widget, otherwise a form would handle accelerators meant for another form.

If you place a main page you can handle accelerators when the user clicks on a blank area. Or use a desktop and register the accelerators there. If the same accelerator is registered in a form and on the parent desktop (or page) and the user presses Ctrl-P while on the form, the accelerator will only be processed by the form that contains the focus.

To debug in the browser, use F12 and place a break in wisej.js __onAccelerator: function (e) {…

HTH

Best,

Luca

  • You must to post comments
0
0

Yes.  Accelerators generally work.  I can catch a P, for example, but not a ctrl-P.  I assume this is because the browser is catching it before WiseJ.  Am I correct in assuming that?  And, if so, am I on the right track to prevent the browser from catching it?

  • You must to post comments
0
0

Did you try the Accelerators property on the main page or on form?

  • You must to post comments
Showing 4 results
Your Answer

Please first to submit.