Introduction
I decided to write this article because it took me a long time to find an answer to this question, and surprisingly, most places I searched gave me the answer that this task is impossible on XP!
Well, it is possible!!!
Locking the keyboard and mouse and using SendKeys to an application window
Here is a simple VB.NET code which demonstrates how to do this:
Imports System.Windows.Forms
Public Class WinControl
Declare Function BlockInput Lib "User32" _
(ByVal fBlockIt As Boolean) As Boolean
Public Shared Function Wait2Send(ByVal caption As String, _
ByVal keys As String, ByVal seconds As Integer)
Dim success As Boolean = False
Dim now As DateTime = DateTime.Now
BlockInput(True)
While (success = False And (DateTime.Now.Subtract(now).Seconds _
< seconds Or seconds = 0))
Try
AppActivate(caption)
SendKeys.SendWait(keys)
success = True
Catch
System.Threading.Thread.Sleep(100)
End Try
End While
BlockInput(False)
End Function
End Class
Here is an example of using this function:
WinControl.Wait2Send("Calculator","22*22{ENTER}",30);
In this example, the function will wait 30 seconds for some application window with the caption: "Calculator" to appear. While waiting, it locks the keyboard and mouse.
If such an application window exists or will appear in the given 30 seconds, it will be given the key stroke - 22*22 and then the ENTER special key. If you activate your calculator, you will get the result to this calculation.
You can get further help on:
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.