按住Shift键的同时按下箭头键 [英] Arrow key pressed while shift key is held down

查看:129
本文介绍了按住Shift键的同时按下箭头键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个

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. The cells that are already set are <input> tags like the rest, but they have the readonly attribute. 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.

因此,向下第三个单元格(从左数第五个单元格)的ID为'c3-5'.每个单元格都有一个ID,因此我认为可编辑的输入将具有类似 onkeyup ="shiftArrows(this)" 的属性.我的问题是我要在 shiftArrows()中放入什么?

So, the third cell down, fifth from the left would have an id of '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)". My question is what do I put in shiftArrows()?

它可能始于以下内容:

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

,但是然后我必须测试在按下Shift键的同时是否按下了箭头键.如果按下 shift + down shift + up 且其正上方或正下方的单元格为'readonly',则它将转到对一个,然后再次检查.如果那是'readonly',它将转到左边的两个,并且会像这样继续检查.如果按下 shift + right ,它将一直向右移动直到找到一个空的,或者如果需要的话跳到下一行.对于 shift + left 也是如此.

but then I have to test if an arrow key is being pressed while the shift key is down. 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. If that is 'readonly', it would go to the left two, and would keep checking like that. 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. Same thing for shift+left.

无论如何,我可能可以这样做,但是我不知道如何在按住Shift键的同时测试是否按下了箭头.

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.

推荐答案

此操作是否可以处理您需要的操作?

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 Fiddle: http://jsfiddle.net/stroz/hrQEX/3/

这篇关于按住Shift键的同时按下箭头键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆