Click to See Complete Forum and Search --> : Recoginition of keypress thru API(Window API)
diwakar
Aug 23rd, 2000, 07:57 AM
hi,
is it possible to know whether any key is pressed in the
form using window API. If yes then how???
And after that is detected I want to call a function Which
will do certain activity.
Please tell me how to do it
thx
k_diwakar2000@yahoo.com.sg
gwdash
Aug 23rd, 2000, 08:26 PM
use GetAsyncKeyState and poll, but why not just use the Form_KeyPress Event with the KeyPreview property set to True?
Here is an example of how to use the GetAsyncKeyState api:
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Private Sub Timer1_Timer()
Dim iKey As Integer
For iKey = 0 To 255
If GetAsyncKeyState(iKey) Then Caption = "KeyCode: " & iKey & " was pressed."
Next
End Sub
Numbers 2 and below represent a NullCharacter, left mouse and right mouse respectively. If you don't want to capture them, simply start from 3.
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Private Sub Timer1_Timer()
Dim iKey As Integer
For iKey = 3 To 255
If GetAsyncKeyState(iKey) Then Caption = "KeyCode: " & iKey & " was pressed."
Next
End Sub
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.