-1

I have written a vb.net application to start an external application (notepad.exe) and then open the txt file located in at "D:\test.txt". I have used keyboard events to achive this.

Step1: Open the notepad

Process.Start("notepad.exe")

enter image description here

Step 2: Raised the keyboard event Ctrl + O to open the Open dialog box

keybd_event(VK_CONTROL, &H45, 0, 0)
keybd_event(VK_O, 0, 0, 0)
keybd_event(VK_CONTROL, &H45, KEYEVENTF_KEYUP, 0)

Step 3: Wait for 2 seconds.

Thread.Sleep(2000)

Step 4: Raised the keyboard event to type the File path "D:\Test.txt" in the File Name textbox. enter image description here

Issue: Occassionally the Open dialog box operation takes more time (exceeds 2000 ms) to open, as a result the file path typing event started before opening the open dialog box. I have increased the sleep time, but the issue not fixed completely.

enter image description here

Is there any way to check whether the Open dialog box is opened using the notepad process id?

I have tried using EnumChildWindows, but i didn't get the result.

Saravana Kumar
  • 3,669
  • 5
  • 15
  • 35

1 Answers1

0

The PID will change every time you open or close notepad. I would suggest to use the Image Name to check to see if it is open. beware of this option though because if you have to instances open this will cause an issue.

  • Still the other product will always have a different PID number as well –  Oct 08 '15 at 16:40