I found here in stackoverflow a way of calling a function by keypress, but it only works in the forms window. I would like to know a way to make it work in any window. Exemple: i press F1 in the desktop and the desired function runs (we can assume the program is already running, but minimized). The code below works fine but only on its window. Thanks in advance.
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
switch (keyData)
{
case Keys.F1:
F1Start();
break;
case Keys.F2:
F2Stop();
break;
}
return base.ProcessCmdKey(ref msg, keyData);
What you're looking for is a Global Keyboard Hook.
See the accepted answer here (Global keyboard capture in C# application)