-2

I'm making an app that will control my rgb lights and I want it to handle event for clicking specific key, but i want to run it as a background process.

I have already tried using this:

    private void Form1_Load(object sender, EventArgs e)
    {
        this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.Form1_KeyDown);
    }
    private void Form1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
    {
        if (e.KeyCode == Keys.F9)
        {
            Debug.WriteLine("F9 down");
        }
    }

It works, but only if form window is active and visible, so I'm not satisfied. I'm looking for a solution that will work even if the form is invisible.

1 Answers1

0

When a keydown event happens and a form is not focused / active it will not detect the event. However, you can use Win API to create a key listener of sorts. See this link for more details of "Global Hotkeys".

Mac
  • 131
  • 1
  • 7