I'm making a shortcut program in C#. And I've done this piece of code that works, it just print ss when I press shift.
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
while (true)
{
if ((Control.ModifierKeys & Keys.Shift) != 0)
Console.WriteLine("ss");
Thread.Sleep(50);
}
}
}
The problem is that while true is consuming 20% of my cpu so I want to optimize it (I will not increase sleep time) and it need to work from any windows focus (If I'm using another app and i press shift it have to print ss). I just want keep it reactive and decrease cpu usage. Do you know guys any tricks?