Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
574 views
in Technique[技术] by (71.8m points)

keyboard - how to implement shortcut key combination of CTRL or SHIFT + <letter> through javascript?

ASP.NET 2.0 web application, how to implement shortcut key combination of CTRL + Letter, preferably through JavaScript, to make web application ergonomically better? How to capture multiple-key keyboard events through JavaScript?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The short answer is that you use Javascript to capture a keydown event and use that event to fire off a function. Relevant articles:

If you're using the jQuery library, I'd suggest you look at the HotKeys plugin for a cross-browser solution.

I know this is not answering the orginal question, but here is my advice: Don't Use Key Combination Shortcuts In A Web Application!

Why? Because it might break de the usability, instead of increasing it. While it's generally accepted that "one-key shortcut" are not used in common browsers (Opera remove it as default from its last major version), you cannot figure out what are, nor what will be, the key combination shortcuts used by various browser.

Gizmo makes a good point. There's some information about commonly-used accesskey assignments at http://www.clagnut.com/blog/193/.

If you do change the accesskeys, here are some articles with good suggestions for how to do it well:

And you may find this page of Firefox's default Keyboard and Mouse Shortcuts useful (Another version of same information). Keyboard shortcuts for Internet Explorer 7 and Internet Explorer 6. Keyboard shortcuts for Opera and Safari.

You're more likely to run into problems with JAWS or other screen readers that add more keyboard shortcuts.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...