简体   繁体   中英

SendKeys.send is blocked

I have C# application that uses Sendkeys.send to send text to other applications. When executed on windows 7 after some time the Sendkeys stop responding and doesn't send any text. It never happens on windows XP. I suspected the anti virus but it happen also when I'm running with no anti virus. Any ideas what can cause it? Thank you for your help.

What version of the .NET Framework are you compiling against? If you're still using a version prior to 2.0, you are most likely experiencing compatibility problems in Windows 7 as a result of UAC's enhanced security model.

The SendKeys.Send method was updated in version 3.0 of the Framework to work properly with Windows Vista and newer. See the documentation :

The SendKeys class has been updated for the .NET Framework 3.0 to enable its use in applications that run on Windows Vista. The enhanced security of Windows Vista (known as User Account Control or UAC) prevents the previous implementation from working as expected.

You need to upgrade; version 3.5 is already included with Windows 7.

Otherwise, P/Invoking the SendMessage function exposed by the Windows API is an option if you need to send data to other applications. Check pinvoke.net for the declaration you'll need to call this in C#.

There is a (for me, at least) rather strange remark on the MSDN documentation for the SendKeys.Send method:

Caution
If your application is intended for international use with a variety of keyboards, the use of Send could yield unpredictable results and should be avoided.

I do not understand the reason for the statement, but maybe this is (one) cause for the behaviour you ecperience?

At the very bottom of the same MSDN page, they further state:

...The SendKeys class is susceptible to timing issues, which some developers have had to work around. The updated implementation is still susceptible to timing issues, but is slightly faster and may require changes to the workarounds...

Seems to me that SendKey is a function to avoid under all circumstances.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM