简体   繁体   中英

C# keydown event

I am using this code for opening an application from C# keydown event

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.

You should create global hotkey.

Check this one

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. if you want to get key strike any way. you can search in google and codeproject.com for examples of keyboard hook. here are some examples:

example 1

example 2

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