1

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 (i.e. is in the background, minimized, running as service w/o GUI, etc...)

Jeff B
  • 8,572
  • 17
  • 61
  • 140
Medic3000
  • 786
  • 4
  • 20
  • 44

1 Answers1

2

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

Icemanind
  • 47,519
  • 50
  • 171
  • 296