Click to See Complete Forum and Search --> : How to trap key press events ( Key Strokes)


February 24th, 2000, 09:59 PM
Hi Friend ,

I would like to develop an exe in VB which helps me to record each key press event .

-ie- I want to develop a keylogger

The exe should tell me which key has been pressed .

Hoping to get a reply soon .

Mohit.

The Matrix
February 24th, 2000, 10:21 PM
' make a timer and interval to 1
Private Sub Timer1_Timer()
If GetAsyncKeyState(vbKeyControl) <> 0 And GetAsyncKeyState(vbKeyX) <> 0 Then

msgbox "Control and X was pressed!!!!!!"
End If
End Sub
' oh yeah, put this in the forms declarations

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

February 25th, 2000, 01:33 AM
You can trap what key was pressed using "KeyPress Event".
KeyPress Event takes ASCII value of the key pressed as parameter.
You can use the ASCII value to find out which key was pressed.
In VB's HELP,You can get the ASCII value of each and every character on the KeyBoard.This will help you to make your KeyLogger App.

Ravi Kiran
February 25th, 2000, 04:56 AM
GetAsyncKeyState Works. But it is meant to ckeck only ONE key state.

The ideal thing for your requirement is to write a keyboard hook procedure. Writing it in VB really requires a very good knowledge over API. because if you mess up somewhere, you will stop other apps from responding too.

You have to create a hook procedure which follows certain rules. In the sense that it calls the next hook with CallNextHook ?! (or some such thing)

Install it using SetWindowsHookEx.
Look into MSDN for this fn, and i think there should be one example.


RK