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 7779695
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T18:42:14+00:00 2026-06-01T18:42:14+00:00

I am using SendKeys in one of my program (C#) which copies selected text

  • 0

I am using SendKeys in one of my program (C#) which copies selected text when a user presses F8 on keyboard.

It is working fine on Windows 7 but on Windows XP it has the following problem.

  1. Suppose on notepad, following sentence is written “This is test”

  2. If user selects “is” and presses F8 then the text is not copied.

  3. After that if user selects “This” then the text copied is “is”

  4. After that if user selects “test” then the text copied is “This”

As you can see pressing F8 copies previously selected text and not the current one. It is only happening on Windows XP.

Here is the code

System.IntPtr test = GetForegroundWindow();
System.Windows.Forms.SendKeys.Send("^(c)");
string copiedText = Clipboard.GetText();

Since I am using global key binding for F8 hence the first line of code tells me the currently active window. After that Ctrl+C is sent and then text is copied from clipboard.

  • 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-01T18:42:15+00:00Added an answer on June 1, 2026 at 6:42 pm

    I’d suggest switching to using the SendWait method:

    Use SendWait to send keystrokes or combinations of keystrokes to the active application and wait for the keystroke messages to be processed.

    (Emphasis added)

    At the moment, you have a race condition, with no guarantee that the other application has processed the CTRL-C before you attempt to read the clipboard contents. It’s not surprising that sometimes you get the older contents.

    (Insert usual caveats about SendKeys being a horrific way to automate other applications, consider using the automation API instead, and avoid trampling all over the clipboard unless necessary)

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

Sidebar

Related Questions

I can type text into a field using WebElement.sendKeys() but editing doesn't work: I
I'm currently using SendKeys.SendWait(text); in C# but SendKeys sending the key global and I
Background I'm using SendKeys() to send keyboard commands to the active window, but I'm
I have a text box in which when I type one letter say 's'
I have been using SendKeys.Send() & SendKeys.SendWait() to send keys to the foreground program
I have tried all the normal methods of faking keyboard actions (SendInput/SendKeys/etc) but none
I have a Python program that sends keystrokes to another application using SendKeys. Some
I had the tskill operation working fine through a python script when using Python
I am using a multiline text box in which I can type messages ether
Using top it's easy to identify processes that are hogging memory and cpu, 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.