Results 1 to 10 of 10

Thread: How to block window's shortcut keys and function keys?

  1. #1
    Ext User
    Join Date
    Apr 2008
    Posts
    3
    Vote Rating
    0
      0  

    Default How to block window's shortcut keys and function keys?

    Dear all,

    I'm building a web application that running on IE, but I cannot prevent the IE default action for the following shortcut keys:

    - Ctrl+F
    - Ctrl+O
    - Ctrl+P

    And for those window's function keys (F1,F2...F12) also.

    I've add this code in the onReady function:
    Ext.EventManager.on('id_phs_main_page', 'keydown', f_hotkey);
    The function used to cater the shortcut key:
    function f_hotkey(e) {
    if(e.ctrlKey && e.getKey()==70) {
    e.preventDefault();
    f_find();
    e.stopEvent();
    return;
    }
    }
    when I press Ctrl+F, my own handler will be called but the IE default Find dialog still pop up. I'd like to execute my own handler only when user press the shortcut keys and function keys, can anyone help me to solve this problem?

  2. #2
    Ext User
    Join Date
    Apr 2008
    Posts
    131
    Vote Rating
    1
      0  

    Default

    you can solve this problem using javascript instead of extjs

  3. #3
    Sencha User
    Join Date
    Oct 2007
    Location
    Berlin, Germany
    Posts
    891
    Vote Rating
    12
      0  

    Default

    Quote Originally Posted by yazan_rababa View Post
    you can solve this problem using javascript instead of extjs
    uhm..isn't extjs currently pure javascript?

    i guess you meant vbscript?

  4. #4
    Ext User
    Join Date
    Apr 2008
    Posts
    3
    Vote Rating
    0
      0  

    Default

    Quote Originally Posted by yazan_rababa View Post
    you can solve this problem using javascript instead of extjs
    Could you pls show me how to solve the problem using javascript? Thx a lot

  5. #5
    Ext User
    Join Date
    Apr 2008
    Posts
    131
    Vote Rating
    1
      1  

    Default

    write this code in your main html or php file
    Code:
    <script type="text/javascript">
     document.onkeydown = function(){
       if ((event.keyCode == 78) && (event.ctrlKey)){
          alert ("No new window")
          event.cancelBubble = true;
          event.returnValue = false;
          event.keyCode = false;
          return false;
      }
    }
    </script>
    this prevented ctrl+n!

  6. #6
    Ext User
    Join Date
    Apr 2008
    Posts
    3
    Vote Rating
    0
      0  

    Default

    The ExtJS also work on Ctrl+n, but only not working for some keys such as:

    - Ctrl+F
    - Ctrl+O
    - Ctrl+P

    And those window's function keys (F1,F2...F12) also. I've tried your method already but still not working.

  7. #7
    Sencha - Ext JS Dev Team evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    18,438
    Vote Rating
    859
      0  

    Default

    I wouldn't bother trying to do this with javascript. There's certain things you don't have control of. The BEST thing you could do is only catch keypresses when the focus is over the doucment.

    It still doesnt stop the user from using the browser menus to achieve ctrl+f, ctrl+p etc.

  8. #8
    Ext User
    Join Date
    Apr 2008
    Posts
    131
    Vote Rating
    1
      0  

    Default

    Code:
    <script type="text/javascript">
     document.onkeydown = function(){
         var x = event.keyCode;
       if (((x == 70)||(x == 78)||(x == 79)||(x == 80)) && (event.ctrlKey) || (x > 111 && x<124) ){
          //alert ("No new window")
          event.cancelBubble = true;
          event.returnValue = false;
          event.keyCode = false;
          return false;
      }
    }
    </script>
    this disabled using ctrl+o, ctrl+p, ctr+f and F1->F12 in ie6
    ie7 did not disable F1.

  9. #9
    Ext User Starfall's Avatar
    Join Date
    Jan 2008
    Location
    Moscow, Russian Federation
    Posts
    158
    Vote Rating
    0
      0  

    Default

    Well, you're a god of your app, but... Maybe there is a way to build it without the need for using Ctrl+O shortcuts?

    See, the problem could be solved, but also avoided. In this particular case, consider a user who doen't want you to override his favourite browser shortcuts. He would be angry with you and dislike the app.

  10. #10
    Sencha User SurenderBhyan1's Avatar
    Join Date
    Nov 2013
    Location
    INDIA
    Posts
    97
    Vote Rating
    11
      0  

    Default You can distract the Print event in IE in other way

    Hi,

    One cannot override Ctrl + P in IE. Instead you can distract the current event ctrl +P another way.
    Just put an alert message in case of IE saying like Print is disable here. After clicking OK, Print window will not come up.

    Code:
    document.onkeydown = function(){          
      if ((event.keyCode == 80) && (event.ctrlKey)){        
              alert('Print is disable here');         
             event.cancelBubble = true;         
             event.returnValue = false;          
             event.keyCode = false;      
              return false;     
           }   
         }
    Surender Bhyan
    Mohali



Posting Permissions

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