键盘快捷键,用于控制列表框的按钮 [英] Keyboard Shortcut keys for the buttons to control the List boxes

查看:89
本文介绍了键盘快捷键,用于控制列表框的按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个列表框和一些按钮.

我正在尝试使用键盘快捷键来执行按钮单击事件.

也就是说,假设如果我按F1键,则其功能应与我按button1时的功能相同.

I had two list boxes and some buttons.

I am trying to do the button click event by using keyboard shortcut.

That is, suppose if I press F1 key it should perform same as the functionality if I press button1.

Can any please help me how to write the code?

推荐答案

首先,不要使用F1-标准说的是帮助",不是像这样更改密钥分配的好主意-会使用户感到困惑.

其次,处理 KeyPress事件 [ KeyDown事件 [ ^ ]而是使用e.KeyCode参数.

[edit]忘记将KeyDown链接添加到MSDN-OriginalGriff [/edit]
Firstly, don''t use F1 - the standards say that is for "Help" and it is not a good idea to change key allocations like that - it confuses users.

Secondly, handle the KeyPress event[^] (alphanumeric keys), and check what key is passed to you in the e.KeyChar parameter.
For non-alphabetic keys, handle the KeyDown event[^] instead, and use the e.KeyCode parameter.

[edit]Forgot to add the KeyDown link to MSDN - OriginalGriff[/edit]


<script type="text/javascript">
    document.onkeydown = CallClickEvent;    
    function CallClickEvent(e)
    {
        keynum = window.event ? event.keyCode : e.which
        
        if(keynum == 112) //F1
            document.getElementById(''<%=Button1.ClientID %>'').click()
        else if(keynum == 113)//F2
            document.getElementById(''<%=Button2.ClientID %>'').click()    
        else if(keynum == 114)//F3
            document.getElementById(''<%=Button3.ClientID %>'').click()    
        else if(keynum == 115)//F4
            document.getElementById(''<%=Button4.ClientID %>'').click()    
    }
    
    function buttonClicked(ctrl)
    {
        alert(ctrl.id + '' clicked'');
    }
    </script>


 <input id="Button1" type="button" value="Button1"  runat="server"  önclick="buttonClicked(this)" /><input
        id="Button2" type="button" value="Button2" runat="server" onclick="buttonClicked(this)" /><input
            id="Button3" type="button" value="Button3" runat="server" onclick="buttonClicked(this)" /><input>
                id="Button4" type="button" value="Button4"  runat="server"  önclick="buttonClicked(this)" />
/xml></input>


希望 ^ ]可能会给您一个想法.
Hope this[^] might give you an idea.


这篇关于键盘快捷键,用于控制列表框的按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆