问题
Firstly I have seen the following answer https://stackoverflow.com/a/7731051/626442 and it is not quite sufficient for my needs.
I have written an editor which has basic intellisense capabilities (see A New and Full Implementation of Generic Intellisense for an insight). I have implemented some basic SQL Server completion using this editor, but I keep getting intellisense popping up when I type the * key. I want to prevent this. Currently I do the following:
private void TextArea_KeyDown(object sender, KeyEventArgs e)
{
    if (!e.Control && e.KeyCode == Keys.Space || e.Shift)
        return;
    IntellisenseEngine.DisplayCompletion(this, (char)e.KeyValue);
}
I have recently redeveloped my control and I want to build on existing restrictions as to when and when not to show the insight window. A subset of what I want would be:
+------------------------------+-------------------+
¦   ¦ Modifier   ¦ Keys        ¦ Show Completion   ¦
¦---+------------+-------------¦-------------------¦
¦ 1 ¦ Shift      ¦ None        ¦ No                ¦
¦ 2 ¦ Shift      ¦ * (see note)¦ No                ¦
¦ 3 ¦ None       ¦ Space       ¦ No                ¦
¦ 4 ¦ Any        ¦ Arrow Keys  ¦ No                ¦
+------------------------------+-------------------+
et al. Note, the "*" e.KeyCode is D8, this is obviously not keyboard invariant and dependent on locale, hence is not sufficient. 
Essentially I want my SQL intellisense to act like SQL Server Management Studio's (SQLMS), my questions are:
- How can I detect the asterisk char key being pressed independent of keyboard locale. 
- What other key contions should I impose to make to suppress the pop-up of the intellisense window and to make it act like SQLMS? 
I have tried using
private void TextArea_KeyPress(object sender, KeyPressEventArgs e)
{
    if ((Control.ModifierKeys & Keys.Control) != Keys.Control && <Detect Space Bar> || 
         (Control.ModifierKeys & Keys.Shift) == Keys.Shift && e.KeyChar == '*')
    return;
    IntellisenseEngine.DisplayCompletion(this, (char)e.KeyValue);
}
But then I have the problem of detecting the space bar.
Thanks for your time.
回答1:
Check the modified code . Hope it will work
private void TextArea_KeyPress(object sender, KeyPressEventArgs e)
{
    if ((Control.ModifierKeys & Keys.Contro) != Keys.Control && e.KeyChar == ' ' || 
         (Control.ModifierKeys & Keys.Shift) == Keys.Shift && e.KeyChar == '*')
    return;
    IntellisenseEngine.DisplayCompletion(this, (char)e.KeyValue);
}
回答2:
This works for me:
private void Principal_KeyDown(object sender, KeyEventArgs e)
{
    // if no special keys detected (May, Ctrl, etc)
    char keyChar = Convert.ToChar(e.KeyValue);
    if (keyChar == '\u0010')
    {
        // your code 
    }
}
来源:https://stackoverflow.com/questions/38434647/detecting-the-asterisk-key-on-keydown-event