public static void PasteTextToApp(string strText, string strAppName, string strTitle) { foreach (Process p in Process.GetProcessesByName(strAppName)) { if (strTitle != null) { if (p.MainWindowTitle.IndexOf(strTitle) < 0) { continue; } } NativeWIN32.SetForegroundWindow(p.MainWindowHandle); Thread.Sleep(5000); SendMyKeys.SendString(strText); return; } }
public static void ClipBoardToApp(string strAppName, string strTitle) { foreach (Process p in Process.GetProcessesByName(strAppName)) { if (strTitle != null) { if (p.MainWindowTitle.IndexOf(strTitle) < 0) { continue; } } NativeWIN32.SetForegroundWindow(p.MainWindowHandle); Thread.Sleep(1000); SendMyKeys.SendChar((ushort)Keys.V, false, true); return; } }
public static void SendChar(ushort wVk, bool ShiftKey, bool ControlKey) { uint uintReturn; NativeWIN32.INPUT structInput = new NativeWIN32.INPUT(); structInput.type = (uint)1; structInput.ki.wScan = 0; structInput.ki.time = 0; structInput.ki.dwFlags = 0; structInput.ki.dwExtraInfo = 0; if (ControlKey) { structInput.ki.wVk = (ushort)Keys.ControlKey; uintReturn = NativeWIN32.SendInput((uint)1, ref structInput, Marshal.SizeOf(structInput)); } if (ShiftKey) { structInput.ki.wVk = (ushort)Keys.ShiftKey; uintReturn = NativeWIN32.SendInput((uint)1, ref structInput, Marshal.SizeOf(structInput)); } structInput.ki.wVk = wVk; uintReturn = NativeWIN32.SendInput((uint)1, ref structInput, Marshal.SizeOf(structInput)); structInput.ki.dwFlags = NativeWIN32.KEYEVENTF_KEYUP; structInput.ki.wVk = wVk; uintReturn = NativeWIN32.SendInput((uint)1, ref structInput, Marshal.SizeOf(structInput)); if (ShiftKey) { structInput.ki.dwFlags = NativeWIN32.KEYEVENTF_KEYUP; structInput.ki.wVk = (ushort)Keys.ShiftKey; uintReturn = NativeWIN32.SendInput((uint)1, ref structInput, Marshal.SizeOf(structInput)); } if (ControlKey) { structInput.ki.dwFlags = NativeWIN32.KEYEVENTF_KEYUP; structInput.ki.wVk = (ushort)Keys.ControlKey; uintReturn = NativeWIN32.SendInput((uint)1, ref structInput, Marshal.SizeOf(structInput)); } }