Click to See Complete Forum and Search --> : Little better explaination for Detection


Starcraft
February 7th, 2000, 09:13 PM
i no hwo to detect key board press combinations, but i dont no how to detect them anywhere on the desktop, i mean anywhere on the screen. please help

Aaron Young
February 7th, 2000, 10:54 PM
Use the GetAsyncKeyState() API Within a Timer Controls Timer Event, ie.
private Declare Function GetAsyncKeyState Lib "user32" (byval vKey as Long) as Integer

private Sub Form_Load()
Timer1.Interval = 10
End Sub

private Sub Timer1_Timer()
If GetAsyncKeyState(vbKeyControl) <> 0 And GetAsyncKeyState(vbKeyQ) <> 0 then
Caption = "Pressing CTRL + Q"
else
Caption = ""
End If
End Sub



Aaron Young
Analyst Programmer
ajyoung@pressenter.com
aarony@redwingsoftware.com

Astinite
February 7th, 2000, 11:21 PM
Here's a pretty simple way of capturing a key event anywhere:


Put this in a module:

public Declare Function GetKeyState Lib "user32" (byval nVirtKey as Long) as Integer




here's a loop that will constantly look for a keypress of 8 asynchronously:

Do
DoEvents
i = GetKeyState(56)
If i = 1 then
MsgBox "8 was pressed"
Exit Do
End If

Loop