-1

So i'm attempting to make an auto clicker for something, with a gui, im using .net framework for a windows forms project. How ever i'm not sure how to set up a hot key for when the process isn't tabbed in.

    protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
    {
        if (keyData == (Keys.Control | Keys.F))
        {
            // Code
            return true;
        }
        return base.ProcessCmdKey(ref msg, keyData);
    }

is what i'm using, it correctly detects the key press when the gui is tabbed in how ever when it's tabbed out it doesn't work.

With windows forms how do you detect key presses when the app isn't tabbed in

Frosty
  • 1
  • 1
  • 1
    Have you seen https://stackoverflow.com/questions/18291448/how-do-i-detect-keypress-while-not-focused ? – Caius Jard May 04 '20 at 05:22
  • I think by "tabbed in" you mean "has the focus" ? – Caius Jard May 04 '20 at 05:23
  • Also, google for `c# keylogger` - various instructions such as https://null-byte.wonderhowto.com/how-to/create-simple-hidden-console-keylogger-c-sharp-0132757/ abound – Caius Jard May 04 '20 at 05:29
  • You need Win32 API call for it e.g. `RegisterHotKey` from `user32.dll`. I have a code example but for WPF. :( The question is very popular. Try looking for "Register Hotkey", "Global hotkey". – aepot May 04 '20 at 07:00

1 Answers1

0

From my knowledge there are only dirty solutions in C# for creating a hotkey: Recently I used this library for setting a global hotkey.

I hope I could manage to help you.