简体   繁体   中英

How to detect multiple key press keyboard shortcut outside my application

I'm trying to extend the hotkey CTRL + N so that if the user presses CTRL + N it makes a new file, but if they keep CTRL held and press N a second time it opens a new instance of notepad.

Here's the pseudocode of what I'm getting at:

event Key_Down(CTRL)
{
   while(key_Down(CTRL)
   {
    if(Key_isPressed('N')){Ncount++;}
   }
}
event Key_UP(CTRL)
{
    do{
       if(Ncount == 1)
       {
          Create New File to Current Location
       }
       else if(Ncount == 2)
       {
          Open Notepad;
       }
       else if(Ncount >2)
       {
         Ncount=Ncount/2;
       }
    }(while Ncount>2);
 }

I'm not really sure how to phrase something like this in C#, but I want it so these events will be raised even when the program doesn't have focus (ie is in the background, minimized, running as service w/o GUI, etc...)

You need a "keyboard hook". This project will teach you how to make one: http://www.codeproject.com/Articles/19004/A-Simple-C-Global-Low-Level-Keyboard-Hook

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