Results 1 to 12 of 12

Thread: SendKeys.SendWait

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2005
    Posts
    258

    SendKeys.SendWait

    I am trying to sendkeys.sendwait("%FO"), but for some reason it will not send these keys or it sends them but will not wait. I need to make this macro for a program that doesn't have an activeX handle, so it has to be shelled in order to put it as the active window when sendkeys shoots off.



    VB Code:
    1. shell("MyProgramToSendKeysTo")
    2.  
    3. Wait(12) 'my own wait command that works
    4.  
    5. SendKeys.SendWait("%FO")

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    May 2005
    Posts
    258

    Re: SendKeys.SendWait

    Bump, I could still use some help on this problem.


    Thanks!


    Taco

  3. #3
    Member
    Join Date
    Oct 2004
    Location
    Sunderland, UK
    Posts
    53

    Re: SendKeys.SendWait

    VB Code:
    1. SendKeys.SendWait("%FO")
    This will send keys ALT+F followed by O (without ALT). Are these the keys you want to send to the active application ?

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    May 2005
    Posts
    258

    Re: SendKeys.SendWait

    I need to send ALT, then F, then O.

    Basically a macro to Save from the filemenu. Dan't ask, it's for my company program I am working on.

    Thanks for the reply!


    Taco

  5. #5
    Frenzied Member MrGTI's Avatar
    Join Date
    Oct 2000
    Location
    Ontario, Canada
    Posts
    1,277

    Re: SendKeys.SendWait

    This is just a small guess, but if the secondary program isn't the active window, then the send keys command would be applied to your app.
    ~Peter


  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    May 2005
    Posts
    258

    Re: SendKeys.SendWait

    That is understood, but the 2nd app IS the active app. I can check again but if it isn't, how would I go about making it the active window without using a getobject commend? It doesn't seem to have a handle I can grab and processes class doesn't have the option to make a process z-order 0.


    Thanks.


    Taco

  7. #7
    Lively Member
    Join Date
    Nov 2005
    Posts
    65

    Re: SendKeys.SendWait

    VB Code:
    1. Shell("target.bat", AppWinStyle.NormalFocus, True)

    The last true make the rest of the code wait until the program is "finished". Whether that means that the program closes or if it finishes starting up I'm not sure.

    This is in VS .NET 2005.

  8. #8
    Frenzied Member
    Join Date
    Jul 2005
    Posts
    1,168

    Re: SendKeys.SendWait

    thought about using API functions? Find the handle of the window, then send a WM_COMMAND(this basically sends a filemenu command). You may have to use spy++ to find out what the id number of the "Save" menu. But then again, if your not familiar with using API functions, then ignore this message.

  9. #9
    Frenzied Member
    Join Date
    Jul 2005
    Posts
    1,168

    Re: SendKeys.SendWait

    however, if all you need is to make the other app the active window, use this code:


    VB Code:
    1. Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
    2. Public Declare Function BringWindowToTop Lib "user32" Alias "BringWindowToTop" (ByVal hwnd As Integer) As Integer
    3.  
    4. Dim hwnd As Integer
    5. hwnd = FindWindow(vbNullString, "put name of the title bar of app here")  
    6. BringWindowToTop(hwnd)

    just remember though, the app you want to make as the active window must not be currently minimized. It only works if its behind in the background.
    Last edited by benmartin101; Nov 4th, 2005 at 07:06 PM.

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

    Re: SendKeys.SendWait

    Send a message is always going to be safer than using SendKeys. In fact, I'd go so far as to say, never use SendKeys at all. It is a lousy, quick+dirty method of accomplishing something that should be done the "proper" way, with window messages (i.e. SendMessage).

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    May 2005
    Posts
    258

    Re: SendKeys.SendWait

    In VS 2005, How do I get a list of the API calls like in VB6? I would like to research more on this sending messages to the program.


    Thanks to all who reply!!

    Taco

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

    Re: SendKeys.SendWait

    API calls are platform-dependent, so they're the same for each language. Use MSDN

    Just remember to type HWND's as IntPtr's and that what you would make Long's in VB6 you make Integer's in VB.NET.

    VB Code:
    1. Imports System.Runtime.InteropServices
    2.  
    3. <DLLImport("user32"> _
    4. Private Shared Function SendMessageW ( _
    5.     hWnd As IntPtr, _
    6.     uMsg As Integer, _
    7.     wParam As IntPtr, _
    8.     lParam As IntPtr _
    9. ) As IntPtr: End Function
    Last edited by penagate; Nov 5th, 2005 at 04:01 PM.

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