dcsimg
Results 1 to 4 of 4
  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2009
    Posts
    398

    Send Keys to active window with SendKeys.Send

    In the MSDN page related to SendKeys.Send I read:

    If your application is intended for international use with a variety of keyboards, the use of Send could yield unpredictable results and should be avoided.
    VERY WELL... there is only one problem: they don't say what is better to use in their place!
    Last edited by phil2000; Feb 22nd, 2018 at 06:51 PM.

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    98,927

    Re: Send Keys to active window with SendKeys.Send

    You can either send general keyboard input to the active window or not, i.e. send specific text to a specific window. You can use API functions to determine what is the active top-level window and what is the active child window within that and then send specific text to it. The last function would be SendMessage. Before that, it would likely be something like GetActiveWindow, but it's not something I've done myself so I'm not sure. I'm sure some web searching would yield examples. You might also take a look at www.pinvoke.net for Windows API information.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    May 2009
    Posts
    398

    Re: Send Keys to active window with SendKeys.Send

    Ty for the answer.

    1) SendKeys.Send ===> non need to get the handle of the active window
    2) keybd_event API ===> non need to get the handle of the active window, but it seems obsolete
    3) SendMessage API ===> need to get the handle of the active window by GetActiveWindow, and it's a bit more difficult to send keys combinations

    If few words... SendKeys.Send should be the best solution, and I really can't understand why Microsoft does'nt update it.

  4. #4
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    98,927

    Re: Send Keys to active window with SendKeys.Send

    keybd_event is indeed obsolete, but it has been superseded by SendInput. That may or may not suffer from similar issues to SendKeys.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width


×
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.