Solved

Key loger

Posted on 1998-10-22
9
222 Views
Last Modified: 2010-04-30
How do you get a form that does not have focus to "see" what keys are being pressed. I want to make a key loger. I have done this and I tryed to use it but as soon as the form lost focus it stoped logging keys pressed. Please help.
0
Comment
Question by:rpg_rpg
  • 5
  • 4
9 Comments
 

Author Comment

by:rpg_rpg
ID: 1441116
Edited text of question
0
 
LVL 1

Expert Comment

by:Geffl
ID: 1441117
I needed the same functions in my printscreen utility. The API-Call you need is GetAsyncKeyState ...

Here is my example:
Paste this code in a module

Public Declare Function GetKeyboardState Lib "user32" (kbArray As KeyboardBytes) As Long
Public Declare Function SetKeyboardState Lib "user32" (kbArray As KeyboardBytes) As Long
Public Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer

Public Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Public Type KeyboardBytes
    kbByte(0 To 255) As Byte
End Type

Public kbArray As KeyboardBytes
Public Const VK_SNAPSHOT = &H2C
Public Const VK_ALT = &H12

Paste this code in the form_load part

    Do
        If (GetAsyncKeyState(VK_SNAPSHOT)) Then
            If (GetAsyncKeyState(VK_ALT)) Then
                MsgBox "Alt And Print pressed"
            Else
                MsgBox "Print pressed"
            End If
            kbArray.kbByte(VK_SNAPSHOT) = 0
            kbArray.kbByte(VK_ALT) = 0
            SetKeyboardState kbArray
        End If
        DoEvents
        Sleep 25
    Loop

Don´t forget the DoEvents and the sleep, because the endless-loop this would be important for the performance of you app.
0
 

Author Comment

by:rpg_rpg
ID: 1441118
This is really close. But I am not real versed in API. If you could please tell me how to "see" a certen key other then print and alt+print. What is &H2C  and &H12 mean and how did you get those values? I hope you are not mad at my slowness. I know this is a good example. I just don't get it. Thanks...
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 1

Expert Comment

by:Geffl
ID: 1441119
The hexadecimal values are the constants for virtual keys. If you can´t find the definition of the virtual keys in your help-file or the api-text viewer (in constants) post your e-mail adress and i´ll mail it to you.

0
 

Author Comment

by:rpg_rpg
ID: 1441120
Gee... now I really feal dumb... I looked in both places and loaded all aviable files with the api-text viewer and could not find anything at all. Please send email to
Xer_Soft@hotmail.com        

If I had any more points to give you I would. Thanks again...
0
 
LVL 1

Expert Comment

by:Geffl
ID: 1441121
I just sent you the definitions...
0
 

Author Comment

by:rpg_rpg
ID: 1441122
Thanks a lot. I got it to work! Sorry for all the extra work I put you through. You did great. If there was a higher grade or I had more points I would give them to you!!!! OH... You need to answer with some thing... Go ahead.
0
 
LVL 1

Accepted Solution

by:
Geffl earned 200 total points
ID: 1441123
with some thing...

joke!

fine that it works!
0
 

Author Comment

by:rpg_rpg
ID: 1441124
Adjusted points to 205
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question