Results 1 to 5 of 5

Thread: Keyboard recording?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 1999
    Location
    Nashville, TN
    Posts
    114

    Post

    Evening All,

    I use a lot of my programs in Autocad(R14), and the API (in my opinion) is still lacking
    a lot of functionallity. My question is, is there a way to get VB to record the
    keystrokes that I input, then send them to a text box in my program.

    Hmmmmmmmm........

    Thanks in advance,

    Mike

  2. #2
    Hyperactive Member
    Join Date
    Sep 1999
    Posts
    305

    Post

    All I know is that there is something called a hook, and that's what you want. I found one from microsoft called Hooks32, but it's really simple and kind of stupid. I don't know any more, so this is probably a waste of your time. Sigh. Look for hooks though.

  3. #3
    Lively Member
    Join Date
    Jul 1999
    Posts
    99

    Post

    yes, you can do it in vb with API's but i don't know how. i tried researching all about this before but i got bored. i suggest you study about window messages.

  4. #4
    Hyperactive Member onerrorgoto's Avatar
    Join Date
    Aug 1999
    Location
    Sweden
    Posts
    330

    Post

    You can use hooks to trap events from the keyboard mous etc.
    Here is a topic with some code from MSDN.
    http://<a rel="nofollow" href="http:...htm</a> <br />
    I also know that I found a program that you could use to record the key board, I think it was on the MSDN site but now I cant' find it. Maybe it was somewhere else
    I hope this article will help you ab bit on the way.
    I will get back if I remember where I found the that program.

    ------------------
    On Error Goto Bed :0)
    [email protected]



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

    Post

    You can use MessageHooks but this will only work for Activity within your Application unless you link it via a DLL, here's a method I came up with which doesn't use Hooks:
    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 = 1 To 255
            'Use GetAsyncKeyState to Monitor Keypress From Anywhere in the O/S.
            If GetAsyncKeyState(iKey) And iKey &lt;&gt; VK_LSHIFT And iKey &lt;&gt; VK_RSHIFT And iKey &lt;&gt; VK_SHIFT Then Exit For
        Next
        If iKey &lt; 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
    [email protected]
    [email protected]


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