Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SendKeys.SendWait does not send "{ENTER}" in Windows 7

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?

like image 719
jpints14 Avatar asked Apr 23 '12 18:04

jpints14


People also ask

How do I use SendKeys SendWait?

Use SendWait to send keystrokes or combinations of keystrokes to the active application and wait for the keystroke messages to be processed. You can use this method to send keystrokes to an application and wait for any processes that are started by the keystrokes to be completed.

How do I send SendKeys?

To specify that any combination of SHIFT, CTRL, and ALT should be held down while several other keys are pressed, enclose the code for those keys in parentheses. For example, to specify to hold down SHIFT while E and C are pressed, use "+(EC)".

How do I send keystrokes to another app?

There are two methods to send keystrokes to an application: SendKeys. Send and SendKeys. SendWait. The difference between the two methods is that SendWait blocks the current thread when the keystroke is sent, waiting for a response, while Send doesn't.


1 Answers

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
like image 61
Developer Avatar answered Sep 28 '22 17:09

Developer