5

I have tried this in Visual Studio 2008 with XP and Windows 7:

SendKeys.SendWait("sometext{ENTER}{ENTER}")

This is for opening a file in an open file dialog box. It works on XP with VS2008, but when I try on Windows 7, it seems that the {ENTER} keys are not going through.

Is there a known issue with this, or am I doing something wrong?

jpints14
  • 1,361
  • 6
  • 15
  • 24
  • The reason this wasn't working is because Windows 7 was defaulting to not overwrite the file. Just needed to change it to "sometext{ENTER}{LEFT}{ENTER}".. thx though! – jpints14 Apr 24 '12 at 14:39

1 Answers1

7

this should work, you can try using \n as well:

System.Windows.Forms.SendKeys.SendWait("Hello World{ENTER}Testing\n");

This does work on my windows 7 machine. The problem you're having is most likely with the application you're attempting to send the keys to is running under a different privileged account (eg: as Administrator). This will prevent a user level application from sending the keys, unless you run your application as an Administrator as well. Try running Visual Studio as Administrator and testing your code again.

Right click Visual Studio -> Run As Administrator
Developer
  • 2,021
  • 12
  • 11
  • 2
    thank you for this. I have been stuck on this for 3 days because it didn't send the ENTER key to the active window at all until I follow your suggestion running the app as Admin. – Bopha Jun 22 '13 at 00:50