简体   繁体   中英

Setting a hotkey in my asp.net application

I am trying to set a keyboard shortcut in my application to click an actionlink that I currently have. I would like to set "+" as the key. I have tried setting the accesskey to "+", but that would only select the link and not click it. It also only worked for the plus symbol at the top of the keyboard and didn't work for the plus symbol on the num pad.

My current solution:

@Html.ActionLink("Create New", "Create", null, new { accesskey = "+" })

In conclusion, I would like to use the plus on the numpad and I would like the hotkey to click the link instead of just highlighting it.

Thanks

Edit: I now realize that it was just IE that was working this way for accesskeys and that once I used Chrome, it worked perfectly. I normally use Chrome, but I was using IE for debugging.

In a project I use JavaScript to do what you need:

<script language="javascript" type="text/javascript">
       document.onkeydown = function (evt) {
           var isIE = (document.all ? true : false);
           evt = evt || window.event;
           switch (evt.keyCode) {
               case evt.altKey && 49:
                   mod(document.getElementById("<%= mod01.ClientID%>"));
                   break;
               case evt.altKey && 97:
                   mod(document.getElementById("<%= mod01.ClientID%>"));
                   break;
               case evt.altKey && 51:
                   mod(document.getElementById("<%= mod03.ClientID%>"));
                   break;
           }
       };

The elements are asp hyperlinks:

<asp:HyperLink ID="mod03" Text="Example" CssClass="d9"
           runat="server"> </asp:HyperLink>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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