Jongz Puangput
Jongz Puangput

Reputation: 5637

get any input focus element in windows with c#

Is there anyway to get any focus input (textBox) on any screen any app that active in the windows??

I want to create console application that read RFID tag and put the value (result) on any input box

that is focusing. please advise. Is it possible?

Upvotes: 0

Views: 999

Answers (2)

Jeremy Thompson
Jeremy Thompson

Reputation: 65544

You can use this method to Send Keys to the other applications textbox: C# using Sendkey function to send a key to another application

Upvotes: 1

firefalcon
firefalcon

Reputation: 510

You can check to see if any form is active in your windows application. If form is active, then you can check which TextBox in the form has focus:

FormCollection fc = Application.OpenForms;

        foreach (Form frm in fc)
        {
            if (frm != null)
            {
                foreach (TextBox txt in frm.Controls)
                {
                    if (txt.Focused)
                    {
                        txt.Text = "your text";
                    }
                }
            }
        }

Upvotes: 0

Related Questions