2017-06-08 29 views
0

我想使用create two keyboard shorcuts。第一個(keyCode == 80)有效,但不是第二個。我嘗試瞭解決方案here,但沒有成功。

<!DOCTYPE html> 
    <html> 
     <head> 
    <base target="_top"> 
    </head> 
    <body style="background-color: #FFC0CB;"> 

    <p><red> Ctrl + P = 1 color // Ctrl + I = 2 colors</red></p> 
    <p id="log"> </p> 

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> 
    <script> 
    $('.warning-bar:first',parent.document).hide(); 
    $(document).ready(function(){ 
     $(document).keydown(function(e){ 
     // 80=p/81=q/73=i/77=m/cf http://keycode.info/  
     e.preventDefault(); 
     if(e.ctrlKey && e.shiftKey && e.altKey && e.keyCode == 80){  
      $('#log').html('you pressed Ctrl + p'); 
      google.script.run.added(); 
      } 
     if(e.ctrlKey && e.shiftKey && e.altKey && e.keyCode == 77){  
      $('#log').html('you pressed Ctrl + m'); 
      google.script.run.modified();   
     } 
     }); 


    }); 

    </script> 


} 

</body> 
</html> 
+0

燦你提供HTML進行測試? – Darkisa

+0

@Darkisa,我更新了我的問題 – Enora

回答

0

我同時使用Ctrl + Shift + Alt + M鍵和CTRL + SHIFT + ALT + P使用你的代碼得到正確的結果:https://jsfiddle.net/7acakxeg/

我只是去掉了谷歌的腳本和$('.warning-bar:first',parent.document).hide();