CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11
  1. #1
    Join Date
    May 1999
    Posts
    15

    howto send keyboard input to the active application??



    How can I 'feed' the active application (the active window) with virtual keyboard input from an background task?


    thanks for your halp


    K.

  2. #2
    Join Date
    May 1999
    Location
    UK (South)
    Posts
    93

    Re: howto send keyboard input to the active application??



    Surely if the background app is sending the appropriate messages, you can retrieve them within the active app in the normal way.


    Simon P.

  3. #3
    Join Date
    Apr 1999
    Posts
    24

    Re: howto send keyboard input to the active application??



    Try using ::SendMessage(hWndActive,WM_CHAR,nCharCode,nData);


    If nData is between 1 and 15, it is the number of repeats of the character

    (see the help on WM_CHAR for the other values).

  4. #4
    Join Date
    May 1999
    Posts
    15

    Yes, but ...





    Yes, but how do I get the HWND of the active application?


    And..

    .. can I send it to the main window, or do I have to send it th the active window?


    Thanks


    K.

  5. #5
    Join Date
    Apr 1999
    Posts
    24

    Re: Yes, but ...



    It really depends on exactly what you want to do. To get the active window, try using GetForegroundWindow(), to find a specific application window, try using FindWindow(...)

  6. #6
    Join Date
    May 1999
    Posts
    15

    Does't work ...



    I tried it, but it doesn't work.


    Here ist the code:


    HWND hW;

    hW=::GetForegroundWindow ();

    m_nResult=::SendMessage (hW,WM_CHAR,'X',1);


    So why does't it work???

  7. #7
    Join Date
    Apr 1999
    Posts
    19

    Re: howto send keyboard input to the active application??

    You should use the keybd_event API call. This function
    sends the specified keystroke to the window that currently has
    the input focus.
    The keybd_event API call has four parameters:

    BYTE VKeyCode, BYTE ScanCode, DWORD flags, DWORD ExtraInfo

    I just used the first two parameters, and it seemed to work fine...




  8. #8
    Join Date
    Apr 1999
    Posts
    19

    Re: howto send keyboard input to the active application??

    You should use the keybd_event API call. This function
    sends the specified keystroke to the window that currently has
    the input focus.
    The keybd_event API call has four parameters:

    BYTE VKeyCode, BYTE ScanCode, DWORD flags, DWORD ExtraInfo

    I just used the first two parameters, and it seemed to work fine...




  9. #9
    Join Date
    May 1999
    Posts
    15

    Re: howto send keyboard input to the active application??

    Hi Rob,
    I tried it and it seems to work fine.
    But all output is in lower case.
    And for what do I need the 'ScanCode'?


  10. #10
    Join Date
    Apr 1999
    Posts
    19

    Re: howto send keyboard input to the active application??

    The scan code is for the "OEM-dependent hardware scan code". Most applications don't use this scan code. The documentation says that the system converts this guy to a virtual key code anyway.

    As far as case goes, you have to send a different virtual key code to specify case. For example:

    f - 102
    F - 70

    Hope this helps


  11. #11
    Join Date
    Apr 1999
    Posts
    19

    Re: howto send keyboard input to the active application??

    The scan code is for the "OEM-dependent hardware scan code". Most applications don't use this scan code. The documentation says that the system converts this guy to a virtual key code anyway.

    As far as case goes, you have to send a different virtual key code to specify case. For example:

    f - 102
    F - 70

    Hope this helps


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

Featured