Q:
Is there some way to capture (specific key(keyboard stroke
)) ,when the user clicks it as he clicks the specific button
i want.
I 开发者_StackOverflow中文版want to do that , because i have a grid view
with an insert button
in the gridview footer (to create a new row),and for facilitation, instead of using the mouse every time to add a new row, i wanna to capture a specific key as an equivalent to this button.
Yes you can create specific combinations of keyboard strokes to give you shortcuts.
A typical example would be to use Ctrl + S to save some data on the page.
Here is a good tutorial on how to do it with javascript and jQuery http://www.scottklarr.com/topic/126/how-to-create-ctrl-key-shortcuts-in-javascript/
Here's an excerpt of the code:
var isCtrl = false;
document.onkeyup=function(e){
if(e.which == 17) isCtrl=false;
}
document.onkeydown=function(e){
if(e.which == 17) isCtrl=true;
if(e.which == 83 && isCtrl == true) {
//run code for CTRL+S -- ie, save!
return false;
}
}
精彩评论