English 中文(简体)
是否有任何C#执行,或者有办法以关键顺序作为投入?
原标题:Is there any C# implementation or way to have a textbox that takes a key sequence as input?
  • 时间:2010-11-05 12:12:52
  •  标签:
  • c#
  • keyboard

我正在执行一项重大活动,这些活动压制了主要镇压活动,并做了一些魔.。 现在,我要显示比“ControlKey”更友好的东西,因此,你可以在以下法典中看到一个变化。 除我外,我还做了一些事情,如顶端的编号钥匙,即:D2等,然后还有<代码>等。 添加,显示为之。 此外,印刷检查似乎也得到认可。

是否有人失踪?

这对我来说是一个难以描述的问题,但希望你们能够看到我所说的话。 如果我不认为我对评论作出答复,并在我的发言中加以改进。

private int numKeys = 0;
private List<int> shortcutKeys = new List<int>();

private void textBoxRegionKeys_Click(object sender, EventArgs e)
{
    textBoxRegionKeys.SelectAll();
}

private void textBoxRegionKeys_KeyDown(object sender, KeyEventArgs e)
{
    // There are certain keys we want to ignore...
    if (e.KeyCode != Keys.Delete && e.KeyCode != Keys.Back)
    {
        // We can handle this ourselves, thanks
        e.SuppressKeyPress = true;

        // Shortern what we show
        string ret = e.KeyCode.ToString();
        switch (ret)
        {
            case "ControlKey": ret = "Ctrl"; break;
            case "ShiftKey": ret = "Shift"; break;
            case "Menu": ret = "Alt"; break;
        }

        // If we haven t selected anything, we should be appending
        if (textBoxRegionKeys.SelectionLength == 0)
        {
            if (numKeys > 0)
            {
                // Does our key already exist in the list?
                if (shortcutKeys.Exists(x => x == e.KeyValue))
                {
                    return;
                }

                textBoxRegionKeys.Text += " + ";
            }
            textBoxRegionKeys.Text += ret;
            shortcutKeys.Add(e.KeyValue);
            numKeys++;
        }
        else
        {
            textBoxRegionKeys.Text = ret;
            shortcutKeys.Clear();
            shortcutKeys.Add(e.KeyValue);
            numKeys = 1;
        }
    }
}
最佳回答

案文Box KeyDown/KeyPress等将只为可能被接受为案文箱(和相关 mo)投入的钥匙提出。 因此,你不会看到像印刷筛查等处理的关键。 我认为,最好的选择不理想,但你可以超越进程审查或某些其他形式层次的通信拦截器,以获得关于纽约的主要新闻的信息。 ......

protected override bool ProcessKeyPreview(ref Message m)
{
  var keyCode = (Keys)Enum.ToObject(typeof (Keys), m.WParam);

  //Insert some logic 

  return base.ProcessKeyPreview(ref m);
}

当然,只要有价证券交易所的焦点,而且钥匙受到压力,就将采用这种方法,因此,你必须进行某种形式的检查(这再也不理想)。

if(ReferenceEquals(ActiveControl, textBoxRegionKeys)) {}

如果你处理像用户会议这样的事项,那将是非常不可靠的。

如欲了解详情,请查阅。 页: 1 页: 1

<><>Edit>/strong>

稍微挖掘, t头发现对冰 key关键绘图有任何明显的影响。 我只是绘制一份“友好”关键名称地图:

private static readonly Dictionary<Keys, String> KeysMap = new Dictionary<Keys, String>
                                                             {
                                                                { Keys.D1, "1"},
                                                                { Keys.D9, "9"}
                                                             };

做的是:

  String friendlyKeyCode;
  if (!KeysMap.TryGetValue(keyCode, out friendlyKeyCode))
    friendlyKeyCode = keyCode.ToString();

我本人认为,这种做法比大规模开关好......但这也奏效。

问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签