简体   繁体   English

在KeyDown事件上检测星号键

[英]Detecting the Asterisk Key on KeyDown Event

Firstly I have seen the following answer https://stackoverflow.com/a/7731051/626442 and it is not quite sufficient for my needs. 首先,我已经看到了以下答案https://stackoverflow.com/a/7731051/626442 ,它不足以满足我的需求。

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. 我已经使用此编辑器实现了一些基本的SQL Server完成,但是当我输入*键时,会不断弹出智能提示。 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. 注意,“ *” e.KeyCodeD8 ,这显然不是键盘不变的,并且取决于语言环境,因此是不够的。

Essentially I want my SQL intellisense to act like SQL Server Management Studio's (SQLMS), my questions are: 本质上,我希望我的SQL智能感知像SQL Server Management Studio(SQLMS)一样,我的问题是:

  1. How can I detect the asterisk char key being pressed independent of keyboard locale. 如何检测与键盘语言环境无关的星号char键。

  2. 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? 我应该施加哪些其他关键条件来抑制智能感知窗口的弹出并使它像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. 谢谢你的时间。

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);
}

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 
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM