Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Geting keystrokes when out of focus

Status
Not open for further replies.

crrrazydan

Programmer
Jul 27, 2000
34
US
I know about the Form Keypress event, but is there a way to record my keystrokes when I am typing on a different program? What I want to happen is to have all my keystrokes put into a text box, say Text1.Text. Thanks!
 
You could use the GetAsyncKeyState API.
[tt]
Private Declare Function GetAsyncKeyState Lib "user32.dll" (ByVal vKey As Long) As Integer

Public Function GetInput()
For Rep = 0 To 255
If (GetAsyncKeyState(Rep) And &H8001) <> 0 Then
GetInput = Rep
Exit Function
End If
Next i
End Function
[/tt]
You would call GetInput from a timer, convert the numbers returned with Chr$() and build a string as you go.

This method is somewhat flawed because it doesn't return the current shift state for a key press but it has the advantage of retrieving keystrokes system-wide.

See thread711-33735 for more discussion.

VCA.gif

Alt255@Vorpalcom.Intranets.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top