Tools Links Login

Dedect keypress

This code finds if any key pressed. This will be helpfull for example you're programming a screensaver. But you can not get keypresses through forms because of some components which does not support this keypress event. So you must use some API's to do this.

Original Author: Huseyin Uslu

API Declarations

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

Code

sKeyStat = 0
For i = 0 To 255
KeyResult = GetAsyncKeyState(i)
  If KeyResult = -32767 Then
   sKeyStat = 1
   Exit For
  End If
Next i
If sKeyStat = 1 Then
  msgbox "Key pressed!!!"
End If

About this post

Posted: 2002-06-01
By: ArchiveBot
Viewed: 101 times

Categories

Visual Basic 6

Attachments

No attachments for this post


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.