You must activate and set focus to the destination window.
For example, with Notepad =>
Dim hWnd As IntPtr = FindWindow("Notepad", Nothing)
If (hWnd <> IntPtr.Zero) Then
SwitchToThisWindow(hWnd, 1)
SendKeys.Send("x")
End If
Declarations :
<DllImport("User32.dll", SetLastError:=True, CharSet:=CharSet.Auto)>
Public Shared Function SwitchToThisWindow(hWnd As IntPtr, fAltTab As Boolean) As Boolean
End Function
<DllImport("User32.dll", SetLastError:=True, CharSet:=CharSet.Auto)>
Public Shared Function FindWindow(ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
End Function