请教向桌面发送按键或者字符
这两段代码都不行,求助一下
程序代码:
IntPtr hWndParent = (IntPtr)FindWindowEx(0, 0, "WorkerW", null); IntPtr hWndItem; IntPtr hWnd; while (true) { hWndItem = (IntPtr)FindWindowEx((int)hWndParent, 0, "SHELLDLL_DefView", null); if (hWndItem != IntPtr.Zero) { hWnd = (IntPtr)FindWindowEx((int)hWndItem, 0, "SysListView32", "FolderView"); break; } hWndParent = (IntPtr)FindWindowEx(0, (int)hWndParent, "WorkerW", null); } // 激活 // SetActiveWindow(GetDesktopWindow()); // SetActiveWindow(tempHwnd); // SetForegroundWindow(parent); // SetFocus(hWndItem); SendKeys.Send("as"); SendKeys.SendWait("df");
程序代码:
IntPtr pWnd = FindWindow("Progman", null); pWnd = FindWindowEx(pWnd, IntPtr.Zero, "SHELLDLL_DefVIew", null); pWnd = FindWindowEx(pWnd, IntPtr.Zero, "SysListView32", null); // pWnd = FindWindowEx(pWnd, IntPtr.Zero, "SysListView32", "FolderView"); // IntPtr tWnd = new System.Windows.Interop.WindowInteropHelper(this).Handle; SetParent(this.Handle, pWnd); SendKeys.Send("as"); SendKeys.SendWait("df");