如何在Web窗体中按ctrl + q组合键调用c#函数 [英] how to call a c# function on pressing ctrl+q key combination in web form

查看:97
本文介绍了如何在Web窗体中按ctrl + q组合键调用c#函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友....我正在创建订单管理系统的应用......我必须使用键组合来实现某些功能。如何在按下ctrl + q

hello friends.... i am creating an application of order management system... there i have to use key combination for some of functionalities. how can i call a c# code behind function on pressing ctrl+q

推荐答案

时调用函数后面的c#代码这个问题与表单完全无关。而且,它与C#和ASP.NET无关。与ASP.NET唯一相关的是您可以在ASP.NET代码中编写/生成JavaScript,但无论您做什么,所有工作都是通过JavaScript在客户端完成的。您应该处理事件 keydown 并检查关键和关键状态。



这是有用的资源:< a href =http://www.asquare.net/javascript/tests/KeyCode.html> http://www.asquare.net/javascript/tests/KeyCode.html [ ^ ]。



它可能是这样的:

This problem is totally unrelated to forms. Moreover, it is unrelated to C# and ASP.NET. The only relevance to ASP.NET is that you can write/generate JavaScript in ASP.NET code, but all works is done on the client side by JavaScript, no matter what you do. You should handle the event keydown and check the key and key states.

This is the useful resource: http://www.asquare.net/javascript/tests/KeyCode.html[^].

It could be something like this:
window.onkeydown = function(eventInstance) {
    if (
        eventInstance.ctrlKey
        && !eventInstance.shiftKey
        && !eventInstance.altKey
        && !eventInstance.metaKey
        && eventInstance.keyCode == 65)
            alert("Ctrl-A");
}



不管它是否在页面上有任何控件都不会起作用,即使一个人持有键盘焦点。另请注意,我检查了没有按下其他状态键;你可以改变它。



为了测试,我使用'A'而不是'Q',因为浏览器经常使用'Q'(81而不是65)用于其他目的。但是如果你想要Ctrl + Q,请尝试使用它,或者你想要的任何其他东西。



-SA


这篇关于如何在Web窗体中按ctrl + q组合键调用c#函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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