PDA

Click to See Complete Forum and Search --> : Listen to keyboard


Bjarke.ip
Oct 10th, 2000, 04:25 AM
Can a program listen to every keystroke you made, even if it is another program that is active, like a macrorecorder?

Oct 10th, 2000, 06:11 AM
Use the GetAsyncKeyState api function.


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

Private Sub Form_Load()
Timer1.Interval = 1
End Sub

Private Sub Timer1_Timer()
Dim i As Integer
For i = 3 To 255
If GetAsyncKeyState(i) Then Debug.Print Chr(i)
Next
End Sub

Oct 10th, 2000, 03:01 PM
Setting the Timer to 1 will record to fast. Set it to 100 instead.

Oct 10th, 2000, 05:27 PM
Not always Megatron, not if you are a fast typer. Maybe the interval set at 10 or 50? I know you know that 0 to 255 also includes the mouse. Well, have you noticed that if you don't have it directly set at 3 to 255, and you are printing to the Debug Window, it goes crazy with the square boxes. But, as you already noticed, 0 to 2 is mouse buttons and without them, the Debug Window is normal.

Oct 11th, 2000, 02:33 PM
I beg to differ.

A) When making a Key-logger, you go by average typing. There are people who type at speed 10 and people who type at speed 200. After doing several tests, 100 seems like the reasonable number.

B) When making a key logger, don't print to the debug window. Print to a file

C) 0 is not a mouse button. It's 1, 2 and 3, which represent Left, Middle and Right respectivly.

Oct 11th, 2000, 04:41 PM
So it's 0 that's causing all this trouble?

And 1-3 is not?
And printing to the debug window..was just an example.

Oct 11th, 2000, 04:59 PM
Correct. If you log key 0, then things will tend to 'screw up'.

kedaman
Oct 12th, 2000, 02:29 PM
BTW, the timer won't fire the event less than in 53 ms

wolfrog
Oct 13th, 2000, 03:55 AM
in my opinion GetAsyncKeyState isn't a good way to realize a key logger! i wrote a really cool stealth key logger in c++ which installed a global system hook using a API function the name i don't know at this time (maybe SetWindowsHookEx)...
this logger worked PERFECTLY and logged ALL keys you pressed, at every typing speed... i think this is the way the macrorecoders work...

Bjarke.ip
Oct 14th, 2000, 03:41 AM
I would like to have it, please give a link to it, or send it to me at: Bjarke.ip@forum.dk
please tell me the declaration syntax, so I can declare the function.

wolfrog
Oct 14th, 2000, 10:06 AM
as i said, i wrote this app in c++! this program can't be written in visual basic cause you need a real multithreading app...

if you're interested in the stealth functions of my app, i need to say that even this can't be done in basic. the stealth functions hack the export table of some system dlls like kernel32 etc. this code (it's more than 400 lines c++ code!) is really really difficult... i stole it from bo2k, goto www.bo2k.com and download the source code... it took me some days to extract the stealth code but now it works... hahaha...............

if you want to hide an app from the task list in visual basic you need to do a registerserviceprocess call:

Private Declare Function RegisterServiceProcess Lib "kernel32" (ByVal dwProcessID As Long, ByVal dwType As Long) As Long
Private Const RSP_SIMPLE_SERVICE = 1
Private Const RSP_UNREGISTER_SERVICE = 0

Public Sub HideApp()
Dim pid As Long
Dim regserv As Long

pid = GetCurrentProcessId()
regserv = RegisterServiceProcess(pid, RSP_SIMPLE_SERVICE)
End Sub

Public Sub ShowApp()
Dim pid As Long
Dim regserv As Long

pid = GetCurrentProcessId()
regserv = RegisterServiceProcess(pid, RSP_UNREGISTER_SERVICE)
End Sub

Mad Compie
Oct 18th, 2000, 01:38 PM
Meg, VBAPI.COM says that LBUTTON=1, RBUTTON=2 and MBUTTON=4.

http://www.vbapi.com/ref/other/virtualkeycodes.html

Oct 18th, 2000, 02:15 PM
Isn't the middle mouse button = 3?

Or you could just do it this way:

Private Sub Timer1_Timer()
If GetAsyncKeyState(vbLeftButton) Then Caption = "Left"
If GetAsyncKeyState(vbMiddleButton) Then Caption = "Middle"
If GetAsyncKeyState(vbRightButton) Then Caption = "Right"
End Sub


And did anyone ever see the new mouse with 4 buttons. Wonder how you detect that forth button. Or is that what 4 is equal to? :rolleyes:

wolfrog
Oct 19th, 2000, 12:16 PM
hey guys, you should take a look at VC++ include file 'winuser.h':


.
.
.
#define VK_LBUTTON 0x01
#define VK_RBUTTON 0x02
#define VK_CANCEL 0x03
#define VK_MBUTTON 0x04 /* NOT contiguous with L & RBUTTON */
.
.
.



as you can see 0x3 (or &H3 in VB) is used for the CANCEL (=ESCAPE) key!

if you take a look at 'VBCONST.BAS' (search MSDN for that), is says the same:

.
.
.
Global Const KEY_LBUTTON = &H1
Global Const KEY_RBUTTON = &H2
Global Const KEY_CANCEL = &H3
Global Const KEY_MBUTTON = &H4 ' NOT contiguous with L & RBUTTON
.
.
.


i hope, this was a little help!

Mad Compie
Oct 19th, 2000, 02:05 PM
I agree with Matthew.
VB has a lot of built-in constants, so why not using them thoroughly?
It makes our code more readable.

Oct 19th, 2000, 02:23 PM
Matthew Gates: No, the middle button is 4.