Results 1 to 7 of 7

Thread: Recording KeyStrokes

  1. #1
    Lively Member markwel's Avatar
    Join Date
    Jan 01
    Location
    Chennai, India
    Posts
    104
    Dear Friends,

    I want to record all keys when key pressed in anywhere. It is possible?

    please help me.

    Thanx.

  2. #2
    Hyperactive Member Alan777's Avatar
    Join Date
    Jan 01
    Location
    New Zealand
    Posts
    303
    Here is a simple way without subclassing.
    Put code in a module:
    Code:
    Option Explicit
    
    Public KeypressArray(Max) as Byte 
    Private ArrPos as long
    
    Private Declare Function GetAsyncKeyState Lib "user32.dll" (ByVal vKey As Long) As Integer
          
          
    Public Function KeyInput() As Byte
     Dim i As Integer
    
    'Check for keyboard input
     For i = 0 To 255
      If (GetAsyncKeyState(i) And &H8001) <> 0 Then
       ArrPos = ArrPos + 1
       KeypressArray(ArrPos) = i
       KeyInput = i
       Exit Function
      End If
     Next i
    
     KeyInput = 0
    
    End Function
    then use a timer to call this.
    "Today's mighty oak is just yesterday's nut,
    that held its ground."

  3. #3
    Lively Member markwel's Avatar
    Join Date
    Jan 01
    Location
    Chennai, India
    Posts
    104

    Thank You. But...

    Dear Alan777,

    Thanx for your help.

    Now I am trying that.

    But it says (Max) ' Variable Not Found'

    (Public KeypressArray(Max) As Byte
    Private ArrPos As Long)

    Thanx Again Alan777.

  4. #4
    Hyperactive Member Alan777's Avatar
    Join Date
    Jan 01
    Location
    New Zealand
    Posts
    303
    I should have commented that.
    You need to put a number there. The maximum number of keystrokes that you think you will need to record.
    "Today's mighty oak is just yesterday's nut,
    that held its ground."

  5. #5
    Hyperactive Member Alan777's Avatar
    Join Date
    Jan 01
    Location
    New Zealand
    Posts
    303
    I just tried it out to see what happens. You will need to do some fine tuning on it. Using the timer on an interval of 100 it works ok, but if you hold a key down, you will get this repeating in the array. Also, when the form is loading, sometimes some garbage numbers come out, so your array would pick them up too. Just looking at it a bit, subclassing might be the best bet.
    "Today's mighty oak is just yesterday's nut,
    that held its ground."

  6. #6
    Lively Member markwel's Avatar
    Join Date
    Jan 01
    Location
    Chennai, India
    Posts
    104

    Talking Thank you Alan

    Thank you Alan.

    I am trying to do that.

    Thanx.

  7. #7
    Hyperactive Member Alan777's Avatar
    Join Date
    Jan 01
    Location
    New Zealand
    Posts
    303
    Check out Darkangel's thread too. Lord Orwell is going to show us the best way to do this.
    "Today's mighty oak is just yesterday's nut,
    that held its ground."

Posting Permissions

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