Results 1 to 13 of 13

Thread: Capturing keystrokes

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 1999
    Posts
    321

    Talking Code not slow...

    I noticed that the code wasn't slow... it's working good.. however... it captures the keys when they are RELEASED and not PRESSED which is what I want...

    This is perfect for users who type with two fingers on their keyboard. However, more experienced keyboard-users use alot more fingers and they press the next key BEFORE releasing the first one and in some cases the third key also before even releasing the first one (the finger wasn't quick enough to lift before the other two pushed other keys) and release in NOT the same order.

    So when I type 'hello'
    it captures: ehlol (or sometimes 'helo')


    Does anyone know how to improve this code or have any better suggestion? I've looked into C++ examples with keyboard hooking, althoug, I know zip about C so that didn't help me.. and vb could create a reference to it's dll either so I guess it's just doing something vb.

    ANyone know?
    Signed, Rodik ([email protected])
    Programmer,usesVB6ED
    ===========================
    Copyright©RodikCo,2002.

    Dont mind this signature ;] Its old

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 1999
    Posts
    321
    I tried this code too:

    Code:
    Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
    Private Declare Function GetKeyboardState Lib "user32" (pbKeyState As Byte) As Long
    Private Declare Function ToAscii Lib "user32" (ByVal uVirtKey As Long, ByVal uScanCode As Long, lpbKeyState As Byte, lpwTransKey As Long, ByVal fuState As Long) As Long
    
    Private Const VK_SHIFT = &H10   'Used by Win9x
    Private Const VK_LSHIFT = &HA0  'Used by NT
    Private Const VK_RSHIFT = &HA1  'Used by NT
    
    
    
    Private Sub Form_Load()
    Timer1.Interval = 50
    Timer1.Enabled = True
    End Sub
    
    Private Sub Timer1_Timer()
        Dim iKey As Integer
        Dim iAsc As Long
        Dim bKeys(255) As Byte
        
        For iKey = 0 To 255
            'Use GetAsyncKeyState to Monitor Keypress From Anywhere in the O/S.
            If GetAsyncKeyState(iKey) And iKey <> VK_LSHIFT And iKey <> VK_RSHIFT And iKey <> VK_SHIFT Then Exit For
        Next
        If iKey < 256 Then
            'Get the Current Keyboard State For the Shift Keys Etc..
            Call GetKeyboardState(bKeys(0))
            'Conver the Key to it's ASCII Equivilant
            
            Call ToAscii(iKey, 0&, bKeys(0), iAsc, 0&)
            If iAsc Then
                'Store Keypress to Log Here
                Debug.Print Chr(iAsc);
            End If
            DoEvents
            
            While GetAsyncKeyState(iKey)
                'Wait for Key to be Released
            Wend
            
        End If
    
    End Sub

    but the same problem there, when typing fast, I recieve the characters in the wrong order.... ;(

    Anyone have any idea of how to solve this problem?
    Signed, Rodik ([email protected])
    Programmer,usesVB6ED
    ===========================
    Copyright©RodikCo,2002.

    Dont mind this signature ;] Its old

  3. #3
    Guest
    You said something about Keyboard hooking before: Try looking into KeyboardProc. I'm not entirely familiar with it. Here is an article that might help you

  4. #4
    Hyperactive Member wasiq's Avatar
    Join Date
    Jan 2000
    Location
    Karachi, Sindh, Pakistan
    Posts
    274

    Talking

    I made a key logger in windows, it logs all keys that were pressed by the user, and it works fine with me. I think it captures keystrokes even if an advanced user is working, if you'd like i can mail it to you.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 1999
    Posts
    321

    Sure, mail it

    And I'll see if it can help me

    (The source is also highly appreciated)
    Signed, Rodik ([email protected])
    Programmer,usesVB6ED
    ===========================
    Copyright©RodikCo,2002.

    Dont mind this signature ;] Its old

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 1999
    Posts
    321
    I tried looking into the KeyboardProc thing and it seemed to be usefull, however, when running the example program on the page, VB crashed.

    After restarting computer, doing it all over, running it again, crashing it agian.

    VB crashes somewhere in Kernel32.dll which I believe put a stop to what it thought was dangerous thing that vb was doing.


    (if I compile it, and then run it... then only the program crashes, after clicking close, it crashes again, and keeps crashing about 5 or 6 times before finally windows crashes instead and the computer hangs... Anyone with less dangerous ideas?)

    [Edited by Rodik on 07-17-2000 at 05:44 PM]
    Signed, Rodik ([email protected])
    Programmer,usesVB6ED
    ===========================
    Copyright©RodikCo,2002.

    Dont mind this signature ;] Its old

  7. #7
    Guest
    Did you remember to UnHook it?

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 1999
    Posts
    321
    Yeah, remembered to unhook it, the problem is I never get the chance to hook it from the begininng because VB crashes when pushing F5, r who knows.. maybe some of the code is wrong (which I checked about 4 times now) and it stops to debug and because the keyboard is hooked to that program which ceases to exist at debug time, it crashes.



    Besides, when it DID run, it only captured keyboard-events when the program itself had the focus (and not the whole system).


    *sigh*



    Some must know a way to do this??

    [Edited by Rodik on 07-18-2000 at 12:28 AM]
    Signed, Rodik ([email protected])
    Programmer,usesVB6ED
    ===========================
    Copyright©RodikCo,2002.

    Dont mind this signature ;] Its old

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 1999
    Posts
    321

    Angry How uninteresting can a thread be?



    Isn't there ANYONE from those thousands and thousands of members that this board has any knowledge on this matter?

    Is it really so difficult?
    Signed, Rodik ([email protected])
    Programmer,usesVB6ED
    ===========================
    Copyright©RodikCo,2002.

    Dont mind this signature ;] Its old

  10. #10
    Randalf the Red honeybee's Avatar
    Join Date
    Jun 2000
    Location
    off others' brains
    Posts
    4,345

    Well ....

    You look frustrated, now.

    While learning C, I came across something like TSRs, i.e. memory resident programs written in C. I think this info can help you.

    The TSR use something like an Interrupt Vector Table to interrupt various signals that your OS would otherwise receive and act upon. I believe most of the Anti-Virus softwares that provide some kind of hard disk locking (disallowing any write operations on your hdd) also use something like this. If you can get your hands on such stuff, you can trap keystrokes also. The TSR would simply intercept the keyboard messages going to the OS and you would be able to catch them before Windows.

    By the way, all you people are typing it so wide, it does not fit onto my screen. Any ideas?
    I am not a complete idiot. Some parts are still missing.
    Check out the rtf-help tutorial
    General VB Faq Thread
    Change is the only constant thing. I have not changed my signature in a long while and now it has started to stink!
    Get more power for your floppy disks. ; View honeybee's Elite Club:
    Use meaningfull thread titles. And add "[Resolved]" in the thread title when you have got a satisfactory response.
    And if that response was mine, please think about giving me a rep. I like to collect them!

  11. #11
    Guest

    here is a keylogger....

    it works, not very good though....
    add a timer and a textbox to a form, make the textbox MultiLine(set the multiline property to true) and paste this in, it works crappy, but it works


    Code:
    Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
    
    
    
    Private Sub Timer1_Timer()
    
      For i = 13 To 122
        If GetAsyncKeyState(i) <> 0 Then
          Text1 = Text1 & LCase(Chr(i))
        End If
      Next
    
    End Sub
    set the timer's interval to 100



  12. #12
    Randalf the Red honeybee's Avatar
    Join Date
    Jun 2000
    Location
    off others' brains
    Posts
    4,345

    Hacking? ...

    Well no offence meant at anybody.

    But, we had a case of a hacker (or cracker) who got hold of a program to capture keystrokes. He used (and still uses) this program in cybercafes to read the mail that other people type (not to mention loginnames and passwords and credit card numbers.)

    Rodik, are you an aspiring hacker?

    I am not a complete idiot. Some parts are still missing.
    Check out the rtf-help tutorial
    General VB Faq Thread
    Change is the only constant thing. I have not changed my signature in a long while and now it has started to stink!
    Get more power for your floppy disks. ; View honeybee's Elite Club:
    Use meaningfull thread titles. And add "[Resolved]" in the thread title when you have got a satisfactory response.
    And if that response was mine, please think about giving me a rep. I like to collect them!

  13. #13
    Guest

    This one kept me sleepless for weeks

    I have recently written a macro application that required just this sort of key logging.

    At the start of the year I starting hunting around for a decent routine. I kept downloading different examples as competition between programmers began to produce better an better routines.

    Most would still miss a key now and again.
    Then I did a search on http://www.planetsourcecode.com on the phrase 'Key logger'. One of the examples was written by
    Konstantin Tretyakov entitled 'A complete keylogger in delphi'

    It turns out this is a small Delphi DLL which creates a Key Hook. The dll is free and comes with an example VB program on how to use the dll.

    It is by far the best routine I have seen. I am not sure on its exact technical details but it does the job.


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