How can I catch "ctrl+c" keys pressed on listview?
I'm trying like that
private void listviewLogger_KeyUp(object sender, KeyEventArgs e)
{
if (sender != listviewLogger) return;
//if (e.Control && e.KeyData == (Keys.Control | Keys.C))
if (e.Control && e.KeyCode == Keys.C)
CopySelectedValuesToClipboard();
}
but it shows me the combination of LButton | Sift Key when I press ctrl+C:
P.S.: have two languages installed in windows, system Win2012 R2
Update1: thank You for comment! If I log actions, I see this:
e.KeyData: ControlKey
e.KeyCode: ControlKey
e.KeyData: C
e.KeyCode: C
But still cannot catch this key sequence. Code:
private void listviewLogger_KeyUp(object sender, KeyEventArgs e)
{
if (sender != listviewLogger)
return;
Logger("e.KeyData: " + e.KeyData);
Logger("e.KeyCode: " + e.KeyCode);
}
Update2:
Resolved like this. Don't ask my how :-D
if (((e.KeyData & Keys.ControlKey) != Keys.ControlKey) && e.KeyCode == Keys.C)
CopyLogEntriesToClipboard();
Update3:
Previous works for KeyUp event. For KeyDown first code-snippet works
It is better to catch key down event (I've checked it on editor by holding Ctrl+C and switching to another window without releasing the buttons). Please try one more time your first construction. It works for me!
private void listView1_KeyDown(object sender, KeyEventArgs e)
{
if (e.Control && e.KeyCode == Keys.C)
{
Text = "got it";
}
}