Results 1 to 3 of 3

Thread: GetAsyncKeyState(i) / Key

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2008
    Posts
    114

    GetAsyncKeyState(i) / Key

    If any key is pressed on the keyboard I would like the application to say apple.
    Code:
    Private Sub Timer1_Timer()
    Dim KeyResult As Integer
    Dim i As Byte
    
        For i = 1 To 254
    
            KeyResult = GetAsyncKeyState(i)
               If KeyResult = -32767 Then
                    
                    Select Case i
                    
                        Case i < 255
                        
                            MsgBox "apple"
                        
                    End Select
    
                End If
                
            Next
            
        End Sub

  2. #2

    Thread Starter
    Lively Member
    Join Date
    Jan 2008
    Posts
    114

    Re: GetAsyncKeyState(i) / Key

    Got it to work like this but anyway to do it without listbox?

    Code:
    Private Sub Timer1_Timer()
    Dim KeyResult As Integer
    Dim i As Byte
    
        For i = 1 To 254
    
            KeyResult = GetAsyncKeyState(i)
               If KeyResult = -32767 Then
                    
                    Select Case List1.ListIndex
                    
                        Case 0
                        If i < 255 Then
                                           
                        
                            MsgBox "apple"
                        End If
                    End Select
    
                End If
                
            Next
            
        End Sub

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jan 2008
    Posts
    114

    Re: GetAsyncKeyState(i) / Key

    Nvm got it. Just got rid of case select and did it like this. Thanks anyways

    Code:
    Private Declare Function GetAsyncKeyState Lib "user32" _
            (ByVal vKey As Long) As Integer
    
    Private Sub Timer1_Timer()
    Dim KeyResult As Integer
    Dim i As Byte
    
        For i = 1 To 254
    
            KeyResult = GetAsyncKeyState(i)
               
               If KeyResult = -32767 Then
                    
                    If i < 255 Then
                        
                        MsgBox "apple"
                            
                            Else
                    
                    End If
                
                End If
               
            Next
            
        End Sub
    Last edited by Pezster; Dec 19th, 2008 at 11:23 AM.

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