how to send control + L and control + C to another application?
i am working on win application using c#, i want to send control + L and Control + c when firefox is active, to locate addess bar and copy Url and get info from clipboard. i am trying to do this . but i am enable.
how can i do this? activate the Firefox window, send Ctrl+L (activates address bar), send Ctrl+C (copy selection, ie. URL, to clipboard) and read the clipboard.
[return: MarshalAs(UnmanagedType.Bool)] [DllImport("user32.dll", SetLastError = true)] static extern bool PostMessage(IntPtr hwnd, uint Msg, int wParam, int lParam);
private const uint VK_CONTROL = 0x11;
private const uint VK_L = 0x4C;
private const uint VK_C = 0x43;
if (hwndfirfox == Process.GetProcessesByName("firefox")[0].MainWindowTitle)
hwndfirfox = Process.GetProcessesByName("firefox")[0].MainWindowHandle;
if (hwndfirfox != null)
{
PostMessage(hwndfirfox, VK_CONTROL, VK_L, 0);
PostMessage(hwndfirfox, VK_CONTROL, VK_C, 0);
}
this code is giving error, help me .
I saw a post here which states that PostMessage shouldn't be used for simulating keyboard input. You should use SendKeys or SendInput for this.
You may want to consider this article on CodeProject. The SendKeys class on MSDN only appears to allow you to send keystrokes to the currently active application, which may be helpful to you as well.
链接地址: http://www.djcxy.com/p/63596.html