CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2004
    Location
    Alaska
    Posts
    87

    Get all key pressed since Pc was turned on

    is it possible to get the letters that have been typed? since the computer has been turned on? thanks in advanced

  2. #2
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: Get all key pressed since Pc was turned on

    You could write to a file all key pressed since your program started and till
    your program ended.
    You will need a lot of free space on disk if Pc is not going to be turned off in a day
    and there is a speedy typer at keyboard.
    This example from api-guide should give you a push in the correct direction.
    You might need to look also at a low level keyboard hook. Search in Codeguru,
    you will find.
    By the way: you will not be able tyo get what user types when logging in on
    nt/2000/xp systems, even if your program is already started.

    Code:
    'In a module
    Public Const DT_CENTER = &H1
    Public Const DT_WORDBREAK = &H10
    Type RECT
        Left As Long
        Top As Long
        Right As Long
        Bottom As Long
    End Type
    Declare Function DrawTextEx Lib "user32" Alias "DrawTextExA" (ByVal hDC As Long, ByVal lpsz As String, ByVal n As Long, lpRect As RECT, ByVal un As Long, ByVal lpDrawTextParams As Any) As Long
    Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
    Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long
    Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
    Declare Function SetRect Lib "user32" (lpRect As RECT, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
    Global Cnt As Long, sSave As String, sOld As String, Ret As String
    Dim Tel As Long
    Function GetPressedKey() As String
        For Cnt = 32 To 128
            'Get the keystate of a specified key
            If GetAsyncKeyState(Cnt) <> 0 Then
                GetPressedKey = Chr$(Cnt)
                Exit For
            End If
        Next Cnt
    End Function
    Sub TimerProc(ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long)
        Ret = GetPressedKey
        If Ret <> sOld Then
            sOld = Ret
            sSave = sSave + sOld
        End If
    End Sub
    
    'In a form
    Private Sub Form_Load()
        'KPD-Team 1999
        'URL: http://www.allapi.net/
        'E-Mail: KPDTeam@Allapi.net
        Me.Caption = "Key Spy"
        'Create an API-timer
        SetTimer Me.hwnd, 0, 1, AddressOf TimerProc
    End Sub
    Private Sub Form_Paint()
        Dim R As RECT
        Const mStr = "Start this project, go to another application, type something, switch back to this application and unload the form. If you unload the form, a messagebox with all the typed keys will be shown."
        'Clear the form
        Me.Cls
        'API uses pixels
        Me.ScaleMode = vbPixels
        'Set the rectangle's values
        SetRect R, 0, 0, Me.ScaleWidth, Me.ScaleHeight
        'Draw the text on the form
        DrawTextEx Me.hDC, mStr, Len(mStr), R, DT_WORDBREAK Or DT_CENTER, ByVal 0&
    End Sub
    Private Sub Form_Resize()
        Form_Paint
    End Sub
    Private Sub Form_Unload(Cancel As Integer)
        'Kill our API-timer
        KillTimer Me.hwnd, 0
        'Show all the typed keys
        MsgBox sSave
    End Sub
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  3. #3
    Join Date
    Apr 2004
    Location
    Alaska
    Posts
    87

    Re: Get all key pressed since Pc was turned on

    how would i do that to save it to a text file? thanks alot!

  4. #4
    Join Date
    Oct 2003
    Location
    .NET2.0 / VS2005 Developer
    Posts
    7,104

    Re: Get all key pressed since Pc was turned on

    you wouldnt bother.. you'd just download a "key logger" from a hacker site. most of them even tell you what the user did in terms of what windows were opened, switching between programs etc.. used for stealing passwords, creditcard information and other nice things that users type on their keybaords
    "it's a fax from your dog, Mr Dansworth. It looks like your cat" - Gary Larson...DW1: Data Walkthroughs 1.1...DW2: Data Walkthroughs 2.0...DDS: The DataSet Designer Surface...ANO: ADO.NET2 Orientation...DAN: Deeper ADO.NET...DNU...PQ

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured