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

拈花ヽ惹草 提交于 2019-12-03 21:14:10

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/10286086/sendkeys-sendwait-does-not-send-enter-in-windows-7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!