Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to wait for a window to appear before sending keystrok using sendkeys?

How to wait for a window to appear before sending keystrok using sendkeys?

Scheduled Pinned Locked Moved C#
questioncsharphelptutorial
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Paramhans Dubey
    wrote on last edited by
    #1

    Hi Experts, I have an application in C# where i am calling a .reg file using process class. now i want to send keystroke y first and then i need to wait for next megssage box to appear then send enter to it.

    System.Diagnostics.Process.Start(Application.StartupPath + "\\dsnbackup.reg");

            SendKeys.Send("{y}");
            SendKeys.Send("{ENTER}");
    

    now first ket strok is working fine but not the second one. Because the second window takes some time to appear. Can anybody tell me how can i wait for the window to appear first then send the enter key stroke. Please Help Regards, Paramhans Dubey.

    M L 2 Replies Last reply
    0
    • P Paramhans Dubey

      Hi Experts, I have an application in C# where i am calling a .reg file using process class. now i want to send keystroke y first and then i need to wait for next megssage box to appear then send enter to it.

      System.Diagnostics.Process.Start(Application.StartupPath + "\\dsnbackup.reg");

              SendKeys.Send("{y}");
              SendKeys.Send("{ENTER}");
      

      now first ket strok is working fine but not the second one. Because the second window takes some time to appear. Can anybody tell me how can i wait for the window to appear first then send the enter key stroke. Please Help Regards, Paramhans Dubey.

      M Offline
      M Offline
      Mycroft Holmes
      wrote on last edited by
      #2

      Why not put a #n seconds delay between the commands. Find out the windows handle of the dialog and poll the windows collect to detect when it is present.

      1 Reply Last reply
      0
      • P Paramhans Dubey

        Hi Experts, I have an application in C# where i am calling a .reg file using process class. now i want to send keystroke y first and then i need to wait for next megssage box to appear then send enter to it.

        System.Diagnostics.Process.Start(Application.StartupPath + "\\dsnbackup.reg");

                SendKeys.Send("{y}");
                SendKeys.Send("{ENTER}");
        

        now first ket strok is working fine but not the second one. Because the second window takes some time to appear. Can anybody tell me how can i wait for the window to appear first then send the enter key stroke. Please Help Regards, Paramhans Dubey.

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #3

        Hi, the quick and dirty solution is by inserting a sufficiently large delay (Thread.Sleep). the higher performance solution I typically use needs some P/Invoke to Win32 functions such as GetForegroundWindow and GetWindowText, all in a polling retry-and-sleep loop. :)

        Luc Pattyn


        Local announcement (Antwerp region): Lange Wapper? Neen!


        P 1 Reply Last reply
        0
        • L Luc Pattyn

          Hi, the quick and dirty solution is by inserting a sufficiently large delay (Thread.Sleep). the higher performance solution I typically use needs some P/Invoke to Win32 functions such as GetForegroundWindow and GetWindowText, all in a polling retry-and-sleep loop. :)

          Luc Pattyn


          Local announcement (Antwerp region): Lange Wapper? Neen!


          P Offline
          P Offline
          Paramhans Dubey
          wrote on last edited by
          #4

          By Replacing

          System.Diagnostics.Process.Start(Application.StartupPath + "\\dsnbackup.reg");

          with

          System.Diagnostics.Process.Start("RegEdit.exe", "/S " + '"'.ToString() + Application.StartupPath + "\\dsnbackup.reg" + '"'.ToString());

          solved my problem. /S is used for merger in silent mode.

          P L 2 Replies Last reply
          0
          • P Paramhans Dubey

            By Replacing

            System.Diagnostics.Process.Start(Application.StartupPath + "\\dsnbackup.reg");

            with

            System.Diagnostics.Process.Start("RegEdit.exe", "/S " + '"'.ToString() + Application.StartupPath + "\\dsnbackup.reg" + '"'.ToString());

            solved my problem. /S is used for merger in silent mode.

            P Offline
            P Offline
            Paramhans Dubey
            wrote on last edited by
            #5

            Thanx anyways guys for your replies.

            1 Reply Last reply
            0
            • P Paramhans Dubey

              By Replacing

              System.Diagnostics.Process.Start(Application.StartupPath + "\\dsnbackup.reg");

              with

              System.Diagnostics.Process.Start("RegEdit.exe", "/S " + '"'.ToString() + Application.StartupPath + "\\dsnbackup.reg" + '"'.ToString());

              solved my problem. /S is used for merger in silent mode.

              L Offline
              L Offline
              Luc Pattyn
              wrote on last edited by
              #6

              Hi, I have two comments: 1. What you say does not achieve "i want to send keystroke y first and then i need to wait" at all. Make sure you ask the right question in future. 2. There is a shorthand for '"'.ToString(), it is "\"" and you can even merge it with a previous string literal. :)

              Luc Pattyn


              Local announcement (Antwerp region): Lange Wapper? Neen!


              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups