C # Detect Key Press, don't use enter keys

Is there a way to jump to the method if the key pressed does not result in dialing. those. shift key, control key, etc., without specifying all of them. Ideally for detecting keyboard shortcuts like Control + V = Paste.

Code similar to the one below is what I work with;

    if( (e.KeyData == Keys.Left) 
        || (e.KeyData == Keys.Right) 
        || (e.KeyData == Keys.Home) 
        || (e.KeyData == Keys.End) 
        || (e.KeyData == Keys.Up) 
        || (e.KeyData == Keys.Down)
        || (e.KeyData == Keys.ShiftKey)
        || (e.KeyData == Keys.ControlKey)
        ) return;

But you do not need to add each key combination.

Any ideas?

+3
source share
4 answers
protected override bool ProcessCmdKey( ref Message msg, Keys keyData )
{
  if ( keyData == (Keys.Control | Keys.V) )
    return true;
  else
    return base.ProcessCmdKey( ref msg, keyData );
}

+ . OnKeyPress Char.IsDigit / Char.IsLetter( Char.IsLetterOrDigit), . , , , .

+4

Keys . , . :

if ( (keyData & Keys.Control) == Keys.Control && (keyData & Keys.V) == Keys.V) 
{ 
// Ctrl+V was pressed! 
} 

, ... : s

: http://www.go4expert.com/forums/showthread.php?t=713

+2

: " , - ", , , ,

TextChanged TextBox/RichTextBox. , ( ).

private void richTextBox1_TextChanged(object sender, EventArgs e) {
    // Handle the event.
}

, , Modified .

if (richTextBox1.Modified) {
    // The user modified the contents of the text box.
}

, , , KeyDown, KeyUp, KeyPress .. , , .

0

, " ", .

, unicode " " ('Cc').

-1

Source: https://habr.com/ru/post/1775106/


All Articles