I have written a small Console application which Copies the highlightes text from a web application. I am trying to do it two ways
1) via simple Sendkeys
SendKeys.SendWait("^C");
Application.DoEvents();
2) via SendInput
Keyboard.SimulateKeyStroke('c', ctrl: true);
public static void SimulateKeyStroke(char key, bool ctrl = false, bool alt = false, bool shift = false)
{
List<ushort> keys = new List<ushort>();
if (ctrl)
keys.Add(VK_CONTROL);
if (alt)
keys.Add(VK_MENU);
if (shift)
keys.Add(VK_SHIFT);
keys.Add(char.ToUpper(key));
INPUT input = new INPUT();
input.type = INPUT_KEYBOARD;
int inputSize = Marshal.SizeOf(input);
for (int i = 0; i < keys.Count; ++i)
{
input.mkhi.ki.wVk = keys[i];
bool isKeyDown = (GetAsyncKeyState(keys[i]) & 0x10000) != 0;
if (!isKeyDown)
SendInput(1, ref input, inputSize);
}
input.mkhi.ki.dwFlags = KEYEVENTF_KEYUP;
for (int i = keys.Count - 1; i >= 0; --i)
{
input.mkhi.ki.wVk = keys[i];
SendInput(1, ref input, inputSize);
}
}
I m highlighting the text on web application in Chrome and running my console application thru a ShortKey.
It works (from both ways), when I highlight a label field.
but it doesn't work (neither from method 1 or method2 ) when I highlight any input field.
For ex. My web application has label Contact 2 (above pic) and next it it input field. When I highlight Lable i.e Contact2 (by double clicking) and run my console application (by pressing shorkey), i get highlighted text but when i do that same for input field, i get nothing.
Why is it so that Chrome is accepting Copy commnad for label but not for input.
Any help is appreciated.