How to invoke SendInput() Windows API. was Re: How do I paste into a different app?

Bill Vlahos bvlahos at mac.com
Mon Mar 8 01:25:03 EST 2010


I found this on Microsoft's developer site but I don't know how I can implement it.

> 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.
> 
> 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. The SendKeys class tries to use the previous implementation first, and if that fails, uses the new implementation. As a result, the SendKeys class may behave differently on different operating systems. Additionally, when the SendKeys class uses the new implementation, the SendWaitmethod will not wait for messages to be processed when they are sent to another process.
> 
> If your application relies on consistent behavior regardless of the operating system, you can force the SendKeys class to use the new implementation by adding the following application setting to your app.config file.
> 
> <appSettings>
> 	<add key="SendKeys" value="SendInput"/>
> </appSettings>
> 
> To force the SendKeys class to use the previous implementation, use the value "JournalHook" instead.

Bill Vlahos
_________________
InfoWallet (http://www.infowallet.com) is about keeping your important life information with you, accessible, and secure.

On Jan 7, 2010, at 3:02 AM, runrev260805 at m-r-d.de wrote:

> Hi Bill,
> 
> i have done something similar.  You can create a vbs script and let Rev run this.
> 
> I am not very good at VBS, but the following lines show how to insert text into an app.
> 
> ___________________
> Set WshShell = WScript.CreateObject("WScript.Shell") 
> WshShell.Run "winword.exe"
> 'the app is opened. If your app is already running, you do not need this line
> WScript.Sleep 2000          
> 'script stops for 2000 milliseconds to take sure, that the app is running before further proceeding.
> 
> WshShell.AppActivate "Dokument1 - Microsoft Word"    
> 'activates your already running app
> 'between the quotes you have to put the exact name of the app - as it is shown in the title bar of that app
> ' winword also shows the document name in the title bar
> 
> WScript.Sleep 100          
> 'script stops for 100 milliseconds'
> 
> WshShell.SendKeys "This Text should be inserted"   
> 'the text between the quotes is sent to the app
> 
> WScript.Sleep 100          
> WshShell.SendKeys "{enter}"
> 'sends an enter to winword
> WScript.Sleep 100          
> 
> WshShell.SendKeys "This Text should also be inserted"   
> 'the text between the quotes is sent to the app
> 
> ____________________
> 
> Maybe Ken Ray could jump in, as he knows much more about VB and VBS.
> 
> Regards,
> 
> Matthias
> 
> 
> 
> 
> 
> -------- Original Message --------
> Subject: How to invoke SendInput() Windows API. was Re: How do I paste into a different app? (07-Jan-2010 6:42)
> From:    Bill Vlahos <bvlahos at mac.com>
> To:      runrev260805 at m-r-d.de
> 
>> It looks like Microsoft has deprecated the keybd_event API and suggests 
>> using SendInput() instead.
>> 
>> Below is a sample of what needs to be sent. This is a C++ example. How do I 
>> send this from Rev in Windows? It looks similar to what I do with 
>> AppleScript on the Mac? While the send...as applescript commands are 
>> documented in Rev's dictionary I don't see anything similar for Windows 
>> APIs.
>> 
>> INPUT inp[2];
>>   memset(inp,0,sizeof(INPUT));
>>   inp[0].type = INPUT_KEYBOARD;
>>   inp[0].ki.dwFlags = KEYEVENTF_UNICODE; // to avoid shift, and so on
>>   inp[1] = inp[0];
>>   inp[1].ki.dwFlags |= KEYEVENTF_KEYUP;
>> 
>>   for (LPCTSTR p=str; *p; p++) {
>>      inp[0].ki.wScan = inp[1].ki.wScan = *p;
>>      SendInput(2, inp, sizeof(INPUT));
>>   }
>> 
>> Here are some relevant links:
>> http://msdn.microsoft.com/en-us/magazine/cc163867.aspx
>> http://www.codeguru.com/forum/showthread.php?t=377393
>> http://msdn.microsoft.com/en-us/library/ms646310(VS.85).aspx
>> 
>> On Dec 31, 2009, at 7:27 AM, Bill Vlahos wrote:
>> 
>>> I figured it out and have it working on the Mac with AppleScript. I'm not 
>>> using a paste function but the AppleScript "keystroke" function. It looks 
>>> like the Windows API "keybd_event" can do the same type of thing.
>> 
>> Bill Vlahos
>> _________________
>> InfoWallet (http://www.infowallet.com) helps me remember the important 
>> details of my life.
>> 
>> _______________________________________________
>> use-revolution mailing list
>> use-revolution at lists.runrev.com
>> Please visit this url to subscribe, unsubscribe and manage your 
>> subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-revolution
>> 
>> 
>> 
>> 
>> To: use-revolution at lists.runrev.com
> 
> 
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-revolution




More information about the use-livecode mailing list