简体   繁体   English

按住Shift键的同时按下箭头键

[英]Arrow key pressed while shift key is held down

I have a Sudoku puzzle and I want to make it so the user can press the shift key and hold it down while they use the arrow keys to move up and down between cells. 我有一个Sudoku拼图,我想制作它,以便用户在使用箭头键在单元格之间上下移动的同时,按住Shift键并按住不放。 The cells that are already set are <input> tags like the rest, but they have the readonly attribute. 与其余单元格一样,已经设置的单元格是<input>标记,但是它们具有readonly属性。 Each cell has a class of 'puzzle_cells' and an id starting with a 'c' followed directly by the row number they are in, a '-', and then the cell number. 每个单元格都有一类“ puzzle_cells”和一个以“ c”开头的ID,其后直接是它们所在的行号,“-”,然后是单元格号。

So, the third cell down, fifth from the left would have an id of 'c3-5'. 因此,向下第三个单元格(从左数第五个单元格)的ID为'c3-5'。 Every cell has an id, so I'm thinking the inputs that are editable would have an attribute something like this onkeyup="shiftArrows(this)" . 每个单元格都有一个ID,因此我认为可编辑的输入将具有类似onkeyup="shiftArrows(this)"的属性。 My question is what do I put in shiftArrows() ? 我的问题是我应该在shiftArrows()放入什么?

It probably would start with something like: 它可能始于以下内容:

var input_id = $(this).attr('id');

but then I have to test if an arrow key is being pressed while the shift key is down. 但是然后我必须测试在Shift键按下时是否按下了箭头键。 If shift+down is pressed or shift+up and the cell directly above or below it is 'readonly' , then it would go to the right one and check it again. 如果按下shift+downshift+up且其正上方或正下方的单元格为'readonly' ,则它将转到右侧的单元格并再次检查它。 If that is 'readonly' , it would go to the left two, and would keep checking like that. 如果那是'readonly' ,它将转到左边的两个,并且会像这样继续检查。 if shift+right is pressed it would keep going to the right until if finds an empty one, or jump to the next line if it has to. 如果按下shift+right Right,它将一直向右移动直到找到一个空的,或者如果必须的话跳到下一行。 Same thing for shift+left . shift+left

Anyway, I could probably do that, but what I don't know is how to test if a arrow is pressed while the shift key is held down. 无论如何,我可能会这样做,但是我不知道如何在按住Shift键的同时测试是否按下了箭头。

Does this handle what you're after? 这能满足您的需求吗?

if (event.shiftKey && event.which == 38) { 
  //shift was down when up arrow pressed
}

JS Fiddle: http://jsfiddle.net/stroz/hrQEX/3/ JS小提琴: http : //jsfiddle.net/stroz/hrQEX/3/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM