[Solved] How can I respond to a keyboard chord and replace the entered alpha key with a special one?


Here’s one way to accomplish this for all TextBoxes on your Form:

public partial class Form1 : Form
{

    public Form1()
    {
        InitializeComponent();
    }

    protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
    {
        if (this.ActiveControl != null && this.ActiveControl is TextBox)
        {
            string replacement = "";
            TextBox tb = (TextBox)this.ActiveControl;
            bool useHTMLCodes = checkBoxUseHTMLCodes.Checked;

            if (keyData == (Keys.Control | Keys.A))
            {
                replacement = useHTMLCodes ? "á" : "á";
            }
            else if (keyData == (Keys.Control | Keys.Shift | Keys.A))
            {
                replacement = useHTMLCodes ? "Á" : "Á";
            }

            if (replacement != "")
            {
                tb.SelectedText = replacement;
                return true;
            }
        }

        return base.ProcessCmdKey(ref msg, keyData);
    }

}

solved How can I respond to a keyboard chord and replace the entered alpha key with a special one?