Hi Dw

I'm creating a program in Visual Basic 5.0 and what I want is to listen to keyboard keys the main form that I will be using to listen to the keys will be hidden so that is my problem to detect the keys while the form is hidden.
Anyone have an idea of how can I go about doing so?

are you trying to make a keylogger or something ??

No. It a program that check if a certain key on a keyboard has been pressed and hold to execute the command. Just like let say on your program you want to add a feature and in order for a user to execute or use that feature he/she will have to press and hold a certain button. That is what I wanted but anyway I've just managed to solve it my self thank you.

Well, here is a sample

Use this declaration

Private Declare Function GetAsyncKeyState Lib "User32" _
   (ByVal vKey As KeyCodeConstants) As Long

And this is how to use it

Private Function KeyDown(ByVal vKey As KeyCodeConstants) _
    As Boolean
   KeyDown = GetAsyncKeyState(vKey) And &H8000
End Function

Private Sub Timer1_Timer()
   If KeyDown(vbKeyF10) Then MsgBox "You pressed F10" 
End Sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.