Log inUsernamePassword
Log me on automatically each visit    
Register
Register
Log in to check your private messages
Log in to check your private messages
Visual Basic Forum for Visual Basic Programmers VB Forum Index » Knowledge Base

Post new topic   Reply to topic
Detect KeyPress System Wide
View previous topic :: View next topic  
Author Message
Avis
Junior Poster


Joined: 07 Oct 2003
Posts: 510
Location: India

PostPosted: Oct 8th, 2003 04:04 AM    Post subject: Detect KeyPress System Wide Reply with quote

You'll need to add a timer named tmrKey and watch the debug window... Also detects mouse clicks!

Code:
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer

Private Sub Form_Load()
    Dim k As Long
    For k = 0 To 255
        GetAsyncKeyState k
    Next
End Sub

Private Sub tmrKey_Timer()
    Dim k As Long, bAny As Boolean
    For k = 0 To 255
        If GetAsyncKeyState(k) Then
            bAny = True
            Exit For
        End If
    Next
    If bAny Then
       Debug.Print "Key " & Chr$(k) & " pressed" 'This won't show ctrl, alt presses but it still detects them...
    End If
End Sub
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger ICQ Number
Display posts from previous:   
Post new topic   Reply to topic    Visual Basic Forum for Visual Basic Programmers VB Forum Index » Knowledge Base All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Visual Basic Forum runs phpBB | Forum Template © iOptional
VB Resources | SSL | Visual Basic