简体   繁体   English

C#按键事件

[英]C# keydown event

I am using this code for opening an application from C# keydown event 我正在使用此代码从C#keydown事件中打开应用程序

private void Form1_KeyDown(object sender, KeyEventArgs e)
{
    if (e.KeyCode == Keys.F && e.Alt)
    {
        Process.Start(@"c:\ade.exe");
    }
}

It's working perfectly, but when my windows form application is in working mode, I want to work it also when my app is minimized. 它运行正常,但是当我的Windows窗体应用程序处于工作模式时,我想在最小化我的应用程序时也要工作。

You should create global hotkey. 您应该创建全局热键。

Check this one 检查这个

http://www.liensberger.it/web/blog/?p=207 http://www.liensberger.it/web/blog/?p=207

You'll have to use hooking for this, 您必须为此使用钩子

I googled abit for you and came across this website. 我为您搜寻了一点,并浏览了这个网站。 it's a small class that allows you to bind a Hotkey to your application, when once pressed - you can fire an event in your application. 这是一个小类,允许您将热键绑定到您的应用程序,一旦按下它,便可以在应用程序中触发事件。

Well the keydown (keyup, keypress , mousedown, ...) will work when your application is active and the control that you have written the code has the focus. 当应用程序处于活动状态并且编写代码的控件成为焦点时,keydown(keyup,keypress,mousedown等)将起作用。 if you want to get key strike any way. 如果您想以任何方式获得按键提示。 you can search in google and codeproject.com for examples of keyboard hook. 您可以在google和codeproject.com中搜索键盘钩的示例。 here are some examples: 这里有些例子:

example 1 例子1

example 2 例子2

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

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