How can a winforms application accept user input without focus?

I am using a project hosted at http://inputsimulator.codeplex.com/ It uses the standard Microsoft keyboard input for SendKeys, which is a key pressed.

If I need to use my winform as a keyboard to perform keyboard functions, such as Microsoft tool, on-screen keyboard, I have to provide focus for the application that needs to be edited.

Say, for example, I have to print a document in Word, so it has focus. But when I click the form buttons, it switches to my form and nothing is written to Word.

So...

I want to make a form control that does not focus, but does functionally.

+3
source share
2 answers

To do this, the window style flag WS_EX_NOACTIVATE was created. Here is an example of a form that implements it:

public partial class Form1 : Form {
    public Form1() {
        InitializeComponent();
        this.TopMost = true;
    }
    protected override CreateParams CreateParams {
        get {
            var cp = base.CreateParams;
            cp.ExStyle |= 0x08000000; // Turn on WS_EX_NOACTIVATE;
            return cp;
        }
    }
}
+2
source

Source: https://habr.com/ru/post/1784855/


All Articles