简体   繁体   English

如何在没有Shift,Control或Alt要求的情况下为asp.net按钮分配键盘快捷键?

[英]How do I assign keyboard shortcuts to asp.net buttons without Shift, Control, or Alt requirements?

I have a menu of items that are preceded by a number to act as a keyboard shortcut for rapid navigation. 我有一个菜单项,这些菜单项前面有一个数字,可以用作快速导航的键盘快捷键。 Think nine buttons with text like: 考虑带有以下文本的九个按钮:

1 Open
2 Close
3 End

and so on. 等等。 Actual sample button: 实际样本按钮:

<asp:Button ID="bOpen" runat="server" Font-Bold="True" Font-Size="Large" 
            Text="1 Open" Width="100%" onclick="bOpen_Click" AccessKey="1" />

I want the user to press a number on the numpad, on the top row of numbers, or on a handheld external input device to navigate to other pages. 我希望用户在数字键盘,数字的第一行或手持式外部输入设备上按一个数字以导航到其他页面。 Currently, I'm using the AccessKey property, which works for the hand held device (so I don't need help with this part) but not either of the keyboard number sets. 当前,我正在使用AccessKey属性,该属性适用于手持设备(因此在这一部分不需要帮助),但不适用于任何键盘数字集。 On the keyboard, Alt + Shift are required when using AccessKey. 在键盘上,使用AccessKey时需要Alt + Shift。 I don't want multi-key shortcuts. 我不需要多键快捷键。

How do I make it so that a single key press activates these menu items? 我如何才能使一个按键激活这些菜单项?

The solution I ended up using was Javascript/jQuery. 我最终使用的解决方案是Javascript / jQuery。

$(document).keyup(function (e) {
    if (e.keyCode == 49 || e.keyCode == 97) { $("#<%=bOpen.ClientID %>").click(); }
    if (e.keyCode == 50 || e.keyCode == 98) { $("#<%=bClose.ClientID %>").click(); }
    ...(etc)
} 

I included two keycodes per button to account for both the numpad and the top number row. 我为每个按钮提供了两个键控代码,以说明小键盘和最上面的数字行。 I took the keycodes from here: 我从这里获取了密钥代码:

http://www.webonweboff.com/tips/js/event_key_codes.aspx http://www.webonweboff.com/tips/js/event_key_codes.aspx

I also left the AccessKey property alone, so that the external input device will still work the same as before. 我还单独保留了AccessKey属性,以便外部输入设备仍能像以前一样工作。

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

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