CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2003
    Location
    Oxford, OH
    Posts
    12

    Key logging in C#

    Is there any way in C# to create a simple keylogger? Thanks!
    ~Chris

  2. #2
    Join Date
    Nov 2002
    Location
    Singapore
    Posts
    1,890
    what do you mean by keylogger ?

    Paresh
    - Software Architect

  3. #3
    Join Date
    Mar 2003
    Location
    Oxford, OH
    Posts
    12
    Sorry about that, I was just wondering if there was a way to catch all the keystrokes that are going to other applications and log them without affecting the standard keyboard I/O. Basically, I'm trying to find out what happens to my computer when I'm not in my room.
    Thanks!
    ~Chris

  4. #4
    Join Date
    Apr 2003
    Location
    Russia, Omsk
    Posts
    2
    Originally posted by dosman711
    ...I was just wondering if there was a way to catch all the keystrokes that are going to other applications and log them without affecting the standard keyboard I/O. Basically, I'm trying to find out what happens to my computer when I'm not in my room.
    You can catch keys pressed at any window focused and at any time. Here a way to do this via Windows API:
    [DllImport("user32.dll")]
    private static extern short GetAsyncKeyState(int vKey);


    And my own know-how to use above code:

    public static int[] WhichKeysPressedNow()
    {
    System.Collections.ArrayList list =
    new System.Collections.ArrayList();
    for(int i = 0; i < 500; i++)
    {
    if (GetAsyncKeyState(i) != 0)
    {
    list.Add(i);
    }
    //list.Add((int)GetAsyncKeyState(i));
    }
    int[] res = new int[list.Count];
    for(int i = 0; i < list.Count; i++)
    {
    res[i] = (int)list[i];
    }
    return res;
    }


    Now you can at any time see, which keys are pressed using my function "WhichKeysPressedNow". You can insert this function into an Timer code and check which keys are pressed each ... 20 ms. (this is faster than keys is possible to be pressed).
    Oobe = Out Of Body Experience

  5. #5
    Join Date
    Nov 2002
    Location
    Singapore
    Posts
    1,890
    this can be done without using user32.dll.
    however you will need to implement the key events. if you capture it properly then the game is on your side.

    I agree that at some point user32.dll or some system native dll reference needs to be mentioned.


    -Paresh
    - Software Architect

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