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

  • Home
  • SEARCH
  • 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 7191877
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:49:18+00:00 2026-05-28T19:49:18+00:00

I am writing an application that responds to keyboard actions. To automate testing, I

  • 0

I am writing an application that responds to keyboard actions. To automate testing, I wrote a keyboard simulator that uses User32.dll / SendInput to automate key presses and releases. This approach works fine on the local developer machine, but fails when checked-in and run on a TFS build agent. My guess is that the user mode activities are not getting processed as expected because it is being run as a service. Is there a way to automate keyboard presses and releases that is compatible with automated testing as a service?

Setup:
Hosted TFS (tfspreview.com)
Visual Studio 2010 Ultimate
MSTest, xUnit.NET
Windows 7 Pro (dev)
Windows 2008 R2 (build controller / build agent)

Offending code:

Test case:

            KeyboardSimulator.PressKey(Keys.A);

Keyboard Simulator:

    public static void PushKeyDown(Keys key)
    {
        SendKeyboardInput(key, (uint)FLAGS.NONE);
    }

    public static void ReleaseKey(Keys key)
    {
        SendKeyboardInput(key, (uint)FLAGS.KEYUP);
    }

    public static void PressKey(Keys key)
    {
        PushKeyDown(key);
        ReleaseKey(key);
    }

    #region Internals

    private static KEYBDINPUT createKeybdInput(Keys key, uint flag)
    {
        KEYBDINPUT i = new KEYBDINPUT();
        i.wVk = (ushort)key;
        i.wScan = 0;
        i.time = 0;
        i.dwExtraInfo = IntPtr.Zero;
        i.dwFlags = flag;
        return i;
    }

    private static void SendKeyboardInput(Keys key, uint flag)
    {
        INPUT[] inputs = new INPUT[1];
        inputs[0].type = INPUT_KEYBOARD;
        inputs[0].ki = createKeybdInput(key, flag);
        uint intReturn = SendInput(1, inputs, System.Runtime.InteropServices.Marshal.SizeOf(inputs[0]));
        if (intReturn != 1) throw new ApplicationException("Could not send key");
    }

    [DllImport("User32.dll")]
    private static extern uint SendInput(uint numberOfInputs, [MarshalAs(UnmanagedType.LPArray, SizeConst = 1)] INPUT[] input, int structSize);
  • 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-05-28T19:49:19+00:00Added an answer on May 28, 2026 at 7:49 pm

    The Team Foundation Build server runs as a Windows Service by default. As you guessed, this means that it can’t interact with the desktop (it doesn’t have one).

    You’ll need to configure your build service to run in interactive mode. Follow these steps:

    1. Open the TFS administration console,
    2. Select Build Configuration,
    3. Click Properties on your BuildService
    4. Select Run build service as: Interactive Process

    Of course, you’ll need to remain logged onto that machine for the duration. If it’s a separate build server, you can configure automatic logon and add TfsBuildServiceHost.exe to the automatic startup list. With this configuration, you shouldn’t need to logon to it again.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing an application that uses HTML pages as it's user interface - the
Im writing an application that supposed to send coordinates in an SMS, but I've
I am writing an application that allows a user to place images on a
I am writing an application that will allow an android phone and java application
I am writing an application that sends commands to a unix shell. I am
I'm writing an application that gives the user the option to resize an image
I'm currently writing an application that displays a lot , and I mean, a
I'm writing an application that will create difficult passwords for the user. The user
I'm writing an application that interacts with other processes on a x64 Vista machine.
I'm writing an application that utilizes JavaScript timeouts and intervals to update the page.

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.