KeyLogger (Por decirle de una manera)

(1/1)

igustin:
Vengo haciendo un "KeyLogger" y  lo quiero lograr es que al clickiar una ventana me diga su nombre en el .txt que ya he creado. Lo logre :D pero al tiepo de depurarlo me salta un error:

igustin:
Public Class Form1
    Private Declare Function GetForegroundWindow Lib "user32" () As Long
    Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long

Y he añadido la Private Function:
    Private Function GetActiveWindowTitle() As String
        Dim MyStr As String
        MyStr = New String(Chr(0), 100)
        GetWindowText(GetForeGroundWindow, MyStr, 100)
        MyStr = MyStr.Substring(0, InStr(MyStr, Chr(0)) - 1)
        Return MyStr
    End Function

Pero al tiempo de depurarlo me sale el siguente error:
En:
GetWindowText (Getforegroundwin-dow, mystr, 100)
El mesaje:
Unable to find an entry point named 'GetForegroundWindow' in DLL 'user32.dll'.
please in charge

Alguien sabe porque?? Soy novato y como ven he creado el post varias veces porque he trato de adjuntarlo a las etiquetas, las cuales no he encontrado todavia.

crifesma:
con poco conocimiento que tengo, creo que deberías haber hecho la misma declaración para ambas funciones

Crazy.sx:
Hola, mirá. Yo también hice un keylogger con todos los "chiches" y me funciona de lo más bien. Aquí te dejo una clase que hice para capturar el nombre de la ventana activa.

Espero que te sirva:

Código
Public Class VentanaActiva
#Region " Declaraciones del API de Win32 "
   '
   <System.Runtime.InteropServices.DllImport("user32.dll")> _
   Private Shared Function GetWindowText( _
       ByVal hWnd As System.IntPtr, _
       ByVal lpString As System.Text.StringBuilder, _
       ByVal cch As Integer) As Integer
   End Function
   '
   <System.Runtime.InteropServices.DllImport("user32.dll")> _
   Private Shared Function GetActiveWindow() As System.IntPtr
   End Function
   '
   <System.Runtime.InteropServices.DllImport("user32.dll")> _
   Private Shared Function GetForegroundWindow() As System.IntPtr
   End Function
   '
#End Region
   Dim vRetorno As String
   Public Function CapturaVentana()
 
       ' r
       Dim titulo As New System.Text.StringBuilder(New String(" "c, 256))
       Dim ret As Integer
       Dim nombreVentana As String
 
       Dim hWnd As IntPtr = GetForegroundWindow()
       '
       'If hWnd.Equals(IntPtr.Zero) Then Return
       '
       ret = GetWindowText(hWnd, titulo, titulo.Length)
       'If ret = 0 Then Return
       '
       nombreVentana = titulo.ToString.Substring(0, ret)
       If nombreVentana <> Nothing AndAlso nombreVentana.Length > 0 Then
 
           vRetorno = nombreVentana + "[" + DateTime.Now.ToString("HH:mm:ss") + "] "
 
       End If
 
       Return vRetorno
   End Function
 
 
End Class

Saludos.

Eleкtro:
Eso es lo que pasa por querer hacer las cosas con un Copy/Paste de códigos antiguos de Windows XP o de VB6 xD.

El error es que estás usando el tipo Long, modifica todos los Long por Integer, y listo, funciona.

Saludos!

Navegación

[0] Índice de Mensajes