Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8577341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:08:15+00:00 2026-06-11T20:08:15+00:00

I’m using Keyboard.Type method from the TestApi project in order to enter a string

  • 0

I’m using Keyboard.Type method from the TestApi project in order to enter a string into a text box.

    /// <summary>
    /// Types the specified text.
    /// </summary>
    /// <remarks>
    /// Note that a combination of a combination of Key.Shift or Key.Capital and a Unicode point above 0xFE
    /// is not considered valid and will not result in the Unicode point being types without 
    /// applying of the modifier key.
    /// </remarks>
    /// <param name="text">The text to type.</param>
    public static void Type(string text)
    {
        foreach (char c in text)
        {
            // If code point is bigger than 8 bits, we are going for Unicode approach by setting wVk to 0.
            if (c > 0xFE)
            {
                SendKeyboardKey(c, true, false, true);
                SendKeyboardKey(c, false, false, true);
            }
            else
            {
                // We get the vKey value for the character via a Win32 API. We then use bit masks to pull the
                // upper and lower bytes to get the shift state and key information. We then use WPF KeyInterop
                // to go from the vKey key info into a System.Windows.Input.Key data structure. This work is
                // necessary because Key doesn't distinguish between upper and lower case, so we have to wrap
                // the key type inside a shift press/release if necessary.
                int vKeyValue = NativeMethods.VkKeyScan(c);
                bool keyIsShifted = (vKeyValue & NativeMethods.VKeyShiftMask) == NativeMethods.VKeyShiftMask;
                Key key = (Key)(vKeyValue & NativeMethods.VKeyCharMask);

                if (keyIsShifted)
                {
                    Type(key, new Key[] { Key.Shift });
                }
                else
                {
                    Type(key);
                }
            }
        }
    }

    private static void SendKeyboardKey(ushort key, bool isKeyDown, bool isExtended, bool isUnicode)
    {
        var input = new NativeMethods.INPUT();
        input.Type = NativeMethods.INPUT_KEYBOARD;
        if (!isKeyDown)
        {
            input.Data.Keyboard.dwFlags |= NativeMethods.KEYEVENTF_KEYUP;
        }

        if (isUnicode)
        {
            input.Data.Keyboard.dwFlags |= NativeMethods.KEYEVENTF_UNICODE;
            input.Data.Keyboard.wScan = key;
            input.Data.Keyboard.wVk = 0;
        }
        else
        {
            input.Data.Keyboard.wScan = 0;
            input.Data.Keyboard.wVk = key;
        }

        if (isExtended)
        {
            input.Data.Keyboard.dwFlags |= NativeMethods.KEYEVENTF_EXTENDEDKEY;
        }

        input.Data.Keyboard.time = 0;
        input.Data.Keyboard.dwExtraInfo = IntPtr.Zero;

        NativeMethods.SendInput(1, new NativeMethods.INPUT[] { input }, Marshal.SizeOf(input));
        Thread.Sleep(100);
    }

It works, but it enters the text rather slow. I want to improve the speed. Ideally, it should set the text instantanteously (think of pasting the text into the text field).

Is there an easy way to implement it (setting the text of a text field to some string all at once) in C#?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T20:08:17+00:00Added an answer on June 11, 2026 at 8:08 pm

    Found the answer:

        private void setText(AutomationElement aEditableTextField, string aText)
        {
            ValuePattern pattern = aEditableTextField.GetCurrentPattern(ValuePattern.Pattern) as ValuePattern;
    
            if (pattern != null)
            {
                pattern.SetValue(aText);
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a text area in my form which accepts all possible characters from
Does anyone know how can I replace this 2 symbol below from the string
I am currently running into a problem where an element is coming back from
I have a bunch of posts stored in text files formatted in yaml/textile (from
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.