【问题标题】:Why is it logging only once?为什么它只记录一次?
【发布时间】:2017-10-19 14:23:34
【问题描述】:

您好,我正在为教育目的创建简单的键盘记录器,但我偶然发现了我不知道如何修复的错误

static void WriteLogs(char key)
    {
        StreamWriter file = new StreamWriter(@"C:\Users\Bartek\Desktop\asynckey test\asynckey test\test.txt");

        file.Write(key);

        file.Close();
    }

    static void CatchKeys()
    {
        char key;
        while (true)
        {
            Thread.Sleep(20);

            for (key = (char)8; key <= 190; key++)
            {
                if (GetAsyncKeyState((System.Windows.Forms.Keys)key) == -32768)
                {
                    Console.WriteLine("Logging");
                    WriteLogs(key);
                }
            }
        }
    }

它只将 1 个字符记录到文件中,然后循环继续但不记录

【问题讨论】:

  • 您每次都在覆盖文件。

标签: c# keylogger


【解决方案1】:

尝试追加而不是覆盖:

StreamWriter file = new StreamWriter(
    @"C:\Users\Bartek\Desktop\asynckey test\asynckey test\test.txt", 
    true);   // <- appending instead of recreating

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-06-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多