按enter键,然后自动按shift + tab

问题描述 投票:-1回答:1

当我按下回车键时如何直接按Control + shift?

'activeKeyboard' : function($list){
  var that = this;

  $list.on('focus', function(){
    $(this).addClass('ms-focus');
  })
  .on('blur', function(){
    $(this).removeClass('ms-focus');
  })
  .on('keydown', function(e){
    switch (e.which) {
      case 40:
      case 38:
        e.preventDefault();
        e.stopPropagation();
        that.moveHighlight($(this), (e.which === 38) ? -1 : 1);
        return;
      case 13:
        e.preventDefault();
        e.stopPropagation();
        that.selectHighlighted($list);
        return;
      case 37:
      case 39:
        e.preventDefault();
        e.stopPropagation();
        that.switchList($list);
        return;
    }
  });
},
javascript jquery keyboard jquery-events
1个回答
0
投票

好吧,你的标题提到shift + tab,但是你说你想要ctrl + shift ...无论如何,我会假设你想要ctrl + shift,你可以轻松修改它以适用于shift + tab如果你想要的话。

您可以尝试处理keydown事件,并检查按下的键是否为ENTER,然后模拟按CTRL + shift:

$(document).on("keydown", function(event) {
    if(event.keyCode == 13) { //(i.e. if ENTER is pressed)
         //simulate pressing CTRL + shift
         var e = jQuery.Event("keydown");
         e.which = 16;       // # key code of shift
         e.ctrlkey = true;     // control key pressed
         $(document).trigger(e);// trigger event on document
    }
});
© www.soinside.com 2019 - 2024. All rights reserved.