Total Pageviews

23 Apr 2015

Override Keyboard Keys in SharePoint

Here is a simple way to override keyboard keys in SharePoint:


 overrideKeys = function () {  
 /*This is a standard SharePoint Function, that listens to keyboard events*/  
   window.OnListViewKeyDown = function OnListViewKeyDown(a, b) {  
     var d = GetListContextFromContextNumber(String(b));  
     if (d == null || d.inGridMode) return;  
     var e = a.keyCode,  
       c = a.shiftKey || a.ctrlKey;  
     if (IsCallOutOn()) return;  
           console.log(e);  
     switch (e) {  
       case Sys.UI.Key.del:  
         //Oveeride Delete Button  
         break;  
       case Sys.UI.Key.up:  
         SelectNextRow(b, -1, c, a);  
         break;  
       case Sys.UI.Key.down:  
         SelectNextRow(b, 1, c, a);  
         break;  
       case Sys.UI.Key.enter:  
         if (IsEventTargetAnchor(a)) return;  
         if (a.target != null && !IsStrNullOrEmpty(a.target.className) && a.target.className.indexOf("ms-lstItmLinkAnchor") >= 0) OpenCallOutOrECB(b, a);  
         else ListItem_Open(b, a)  
           case Sys.UI.Key.esc:  
                 //override Esc  
                 brea;  
     }  
   }  
 };  
 $(function () {  
   setTimeout(overrideKeys, 600);  
 });  
You can have a look at the full list of Sys.UI.Keys here