Results 1 to 10 of 10

Thread: Why SendKeys "(^C)" doesn't work?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2000
    Posts
    1,091

    Why SendKeys "(^C)" doesn't work?

    The following works except when it gets to the last part, it doesn't copy the text that's in the text box that has the focus?

    VB Code:
    1. SendKey vbKeyReturn
    2.     SendKey vbKeyTab
    3.     SendKey vbKeyTab
    4.     SendKey vbKeyReturn
    5.     SendKey vbKeyTab
    6.     SendKey vbKeyTab
    7.     SendKey vbKeyTab
    8.     SendKeys "(^C)"

    Visual Studio 2010

  2. #2
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Re: Why SendKeys "(^C)" doesn't work?

    The correct format of sending CTRL+C is:
    VB Code:
    1. SendKeys "^{C}" '^ is outside {}
    Show Appreciation. Rate Posts.

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2000
    Posts
    1,091

    Re: Why SendKeys "(^C)" doesn't work?

    Okay, I think we're getting somewhere but it's acting kinda funky. Basically, what happens is this. When I execute the code as I originally posted, but with your change, it only happens the second time. So, I hit the button on my app and it finds the app I'm looking for and goes through the various SendKey commands to get to the appropriate screen. Once on that screen, a particular textbox gets focus which is what I'm trying to copy with the CTRL C command via SendKeys. However, it doesn't seem to work then. It's only if I hit the button again on my app and then copies the text. So I don't know if it's some sort of memory release issue?

    Visual Studio 2010

  4. #4

  5. #5
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Why SendKeys "(^C)" doesn't work?

    Sendkeys is flaky by nature. Use SendMessage and WM_GETTEXT.

  6. #6
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Re: Why SendKeys "(^C)" doesn't work?

    When the textbox gets the focus, is it selecting the text within it? If not, then you would have to implement that also for CTRL+C to work.

    But as PG said, Sendkeys is not a good way of acheiving this goal. Rather use SendMessage API with the WM_GETTEXT message.
    Show Appreciation. Rate Posts.

  7. #7
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Why SendKeys "(^C)" doesn't work?

    You will also need to use FindWindow and FindWindowEx to get the textbox's window handle for use with SendMessage.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  8. #8

  9. #9
    Addicted Member Beasts's Avatar
    Join Date
    Oct 2006
    Posts
    147

    Re: Why SendKeys "(^C)" doesn't work?

    actually, wat is da textbox is sorta encrypted? like in win live messenger? so dat copyin is disabled? wat do u do then? wud it be da same?

  10. #10
    New Member
    Join Date
    Feb 2011
    Posts
    1

    Re: Why SendKeys "(^C)" doesn't work?

    Hi,

    How to send Numpad "+" keys in code. while trying to send as sendkeys ("{NUMPAD+}"). it just paste the wording in the code. i want the action of "+" keys to be triggered.

    Please help me on this.

    Regards,
    Dinesh

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width