我该如何应对关键presses的特定序列?我该、序列、如何应对、关键

2023-09-07 00:06:05 作者:想太多心会累

最终的结果很简单,我有事情发生时,在字母NOT​​e的次序的用户类型。 '注意'这个词。

The end result is very simple, I have to have something happen when a user types in the letter "n" "o" "t" "e" in that order. 'Note' is the word.

我在做一个小的应用程序的朋友,这将有助于他做笔记,我想我的应用程序变得可见时,在任何地方的计算机上的注意事项,他的类型。

I'm making a little application for a friend that will help him take notes, and I want my application to become visible when he types in "note" from anywhere on the machine.

下面是我有这么远:

if (e.KeyCode == neededLetter as Keys)
            {
                neededLetter = "o";
            }

我初始化为N的 neededLetter 可变的,但我被困在那里。任何帮助?

I initialize the neededLetter variable with "N" but I'm stuck there. Any help?

推荐答案

首先,从你要么需要挂钩所有的键盘输入或找到醒目的字母一些其他的方式,因为他们来在机器上的任何地方做。我不知道如何在C#中完成的,但它应该是可能的。

First, to do it from anywhere on the machine you'll need to either hook all keyboard input or find some other way of catching the letters as they come in. I'm not sure how that's done in C#, but it should be possible.

有关实际打字,你会想是这样(这是不完美的,不一定):

For the actual typing, you'll want something like (this isn't perfect, necessarily):

if (e.KeyCode == neededLetter as Keys)
{
    if ( neededLetter == "n" )
    {
        neededLetter = "o";
    } else if ( neededLetter == "o" ) {
        neededLetter = "t";
    } else if ( neededLetter == "t" ) {
        neededLetter = "e";
    } else if ( neededLetter == "e" ) {
        // you now have the full sequence typed, show your app
    }
} else { // not sure if this is valid, but it's the idea
    neededLetter = "n"; // reset the sequence if another letter is typed
}