I am making an asp.net, c#, webforms web site for sales clerks. I have four main buttons at the top of the screen that I will be using for a lot of functions. What I want to do is set those buttons to F1, F2, F3 and F4 keys on the keyboard.
How will this work? Can I override functions like F1 in IE7? How do I go about implementing this? Does focus have to be on IE7?
Any and all information on this topic is apprecia开发者_运维问答ted.
You'll have to do this with javascript, but there's no way that I'm aware of that will allow you to overload specific browser keys (this is a good thing). You'll still be able to use them, but there won't be a way to disable the default browser behavior. I'd re-evaluate your choice of keyboard shortcuts and see if a better solution exists.
The javascript event onkeypress
is what you're looking for though. Here is a solid example using vanilla javscript. You can also look at jQuery's implementation.
Update A new javascript library called Kibo has been released. It's a fully featured keyboard short-cut handler and would be exactly what you're looking for.
精彩评论