Reputation: 786
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...)
Upvotes: 1
Views: 1255
Reputation: 48686
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
Upvotes: 2