|
|
|
|
|
Dicas
|
|
Visual Basic (Problemas Comuns)
|
|
|
Título da Dica: Capturando teclas digitadas dentro e fora da sua aplicação
|
|
|
|
Postada em 31/7/2003 por cacá
============================================================================================ Coloque num módulo:
Type RECT Left As Long Top As Long Right As Long Bottom As Long End Type
Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer Global Cnt As Long, sSave As String, sOld As String, Ret As String
Dim Tel As Long
Function GetPressedKey() As String For Cnt = 32 To 128 If GetAsyncKeyState(Cnt) <> 0 Then GetPressedKey = Chr$(Cnt) Exit For End If Next Cnt End Function
Sub TimerProc(ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) Ret = GetPressedKey If Ret <> sOld Then sOld = Ret sSave = sSave + sOld End If End Sub
============================================================================================ Num form:
Private Sub Form_Load() SetTimer Me.hwnd, 0, 1, AddressOf TimerProc End Sub
Private Sub Form_Unload(Cancel As Integer) KillTimer Me.hwnd, 0 MsgBox sSave End Sub
============================================================================================ Carregue a aplicação e mude para outros programas, pressione as teclas, volte ao seu programa, quando você fechar o form será exibido um Msgbox com a teclas que você pressionou.
|
|
|
|
|