0% found this document useful (0 votes)
68 views20 pages

kEYLOGGER - Project - Report - Final Copy1

Uploaded by

udayashankark9
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
68 views20 pages

kEYLOGGER - Project - Report - Final Copy1

Uploaded by

udayashankark9
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 20

KEYLOGGER IN PYTHON PROGRMMING

Visvesvaraya Technological University


Jnana Sangama, Belgaum, , Karnataka 590018

A Project Report on
“KEYLOGGER IN PYTHON PROGRAMMING”
Bachelor of Engineering in
Computer Science and Engineering
Submitted by:
UDAYSHANKAR K 1GG22CS052
2nd Semester
Under the Guidance of
Dr. CHETHAN K C

GOVERNMENT ENGINEERING COLLAGE


RAMANAGARA – 562159
2022-23

1
COMPUTER SCIENCE DEPARTMENT
GOVERNMENT ENGINEERING COLLEGE
B.M ROAD RAMANAGARA-562159
Affiliated to VTU Belagavi, Approved by AICTE-New Delhi

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

CERTIFICATE

Certified that UDAYSHANKAR K (1GG22CS052) has submitted mini project report on python
carried out during second semester, as part of internal assessment for the subject INTRODUCTION
TO PYTHON PROGRAMMING (BPCLK205B).

(Signature of the guide)

2
COMPUTER SCIENCE DEPARTMENT
Chapter no. Name Page no.
1 Introduction 05-06
2 Algorithm 07
3 Design& Structure 08
4 Implementation 09-10
5 Program Analysis 11-12
6 Result & Analysis 13-17
7 Conclusion & 18-20
Bibliography

3
COMPUTER SCIENCE DEPARTMENT
CHAP CHAPTER-1: INTRODUCTION TER-1:

INTRODUCTION CHAPTER-1: INTRODUCTION


The "Keyboard Event Recorder" is a Python program that captures keyboard events, such as key
presses and releases, and records them into a file. By utilizing the pynput library, this program
allows users to monitor and control keyboard events in Python. It offers a flexible termination key
option, making it easy for users to customize the program to their preferences. With its user-
friendly interface and efficient key capture mechanism, the "Keyboard Event Recorder" is a
versatile tool suitable for various applications, such as logging user inputs, analysing keyboard
usage patterns, or automating actions based on keyboard events.

FEATURES :
Custom Termination Key: The "Keyboard Event Recorder" offers the convenience of selecting a
termination key according to the user's choice. This allows users to specify any key from the
keyboard to stop the recording process.

Accurate Key Capture: The program efficiently captures key presses and writes their corresponding
character representations into an output file. It gracefully handle keys without character
representations, ensuring a smooth and error-free experience.

Intuitive User Interface: With clear informational messages and easy-to-understand prompts, the
program provides an intuitive user interface. Users can quickly grasp how to start and stop the
keyboard listener without any confusion.

Versatility: The program's adaptability makes it useful for a wide range of applications. It can serve
as a simple key logger, aid in analysing typing patterns, assist in developing macros, or even
contribute to accessibility solution

While the "Keyboard Event Recorder" program can be useful for certain applications, it also
comes with some potential problems that need to be considered:

1. Privacy Concerns: Keylogging activities, even for legitimate purposes, may raise
privacy concerns. Users should be cautious when running such programs on shared or
public computers, as it can inadvertently record sensitive information like passwords or
personal data.

4
COMPUTER SCIENCE DEPARTMENT
CHAP CHAPTER-1: INTRODUCTION TER-1:

INTRODUCTION CHAPTER-1: INTRODUCTION


2. Security Risks: If the "output.txt" file containing key presses is not handled properly, it
can become a security risk if accessed by unauthorized users. Storing sensitive
information in plaintext could lead to data breaches.

3.
4. Resource Consumption: Continuous keyboard event recording can consume system
resources, potentially affecting the overall performance of the machine. Prolonged usage
may lead to higher CPU and memory usage.
5. Interference with Other Applications: Keyboard event listeners can interfere with other
applications that rely on keyboard input. For example, if a gaming application requires
specific key combinations, the listener could disrupt the game's functionality.
6. Unintended Termination: Users might inadvertently stop the listener by pressing the
termination key while the program is running. This could lead to unexpected termination
and incomplete recording of data.
7. Incompatibility: The program might not work as expected on all platforms or
environments due to differences in system configurations, keyboard layouts, or operating
systems.
8. Legal and Ethical Considerations: Depending on the jurisdiction, keylogging activities
may be subject to legal restrictions. Users must be aware of and adhere to applicable laws
and ethical guidelines regarding such activities.
9. Lack of User Awareness: If the program runs silently without user awareness, it may be
considered intrusive and could violate privacy norms.
10. False Positives: Certain keys, especially function keys or special keys, might not have
character representations and can result in AttributeError exceptions. Handling such cases
gracefully is crucial to avoid false positives in error handling.
11. Debugging and Error Handling: Proper error handling and debugging mechanisms
should be in place to prevent unexpected crashes or issues during program execution.

To mitigate these problems, it's essential to provide clear usage instructions,


ensure user consent, and handle data securely. Users should understand the purpose of the
program and exercise caution when using it to avoid any unintended consequences or ethical
concerns.
5
COMPUTER SCIENCE DEPARTMENT
CHAP CHAPTER-1: INTRODUCTION TER-1:

INTRODUCTION CHAPTER-1: INTRODUCTION

1. Start the program


2. Import the necessary library modules
3. Define the termination key and any other desired configuration
4. Define the callback function for key press events

When a key is pressed:

If the key has a character representation:

Write the character to the output file

5. Define the callback function for key release events

When a key is released:

If the released key is the termination key:

Stop the listener and terminate the program

6. Create an instance of the keyboard.Listener class

Set the callback functions for key press and release events

7. Start listening for keyboard events

While the program is running:

Capture key press and release events

If a key is pressed and has a character representation:

Write the character to the output file

8. If the termination key is released:

Stop the listener and terminate the program

9.Program terminates

6
COMPUTER SCIENCE DEPARTMENT
CHAP CHAPTER-1: INTRODUCTION TER-1:

INTRODUCTION CHAPTER-1: INTRODUCTION

7
COMPUTER SCIENCE DEPARTMENT
KEYLOGGER IN PYTHON PROGRMMING

CHAPTER – 3 : DESIGN AND STRUCTURE

This flowchart represents the program's execution flow, starting from initialization until the
program ends or terminates due to the user releasing the termination key. It highlights the main
components, functions, and decision points of the program's design, allowing users to understand
the overall logic and sequence of actions.

start

Import the
library
modules

Define the termination


key and configurations

Define the callback functions for


key press and release

Create an instance of keyboard.listener


class and set callbacks

Start listening for keyboard value

Capture key press and release events

If the key is pressed , write it to the output file

If the termination key is released ,stop the listener

Continue capturing keys until the F12 key is pressed

End the program .

8
COMPUTER SCIENCE DEPARTMENT
KEYLOGGER IN PYTHON PROGRMMING

CHAPTER – 4 : IMPLEMENTATION

9
COMPUTER SCIENCE DEPARTMENT
KEYLOGGER IN PYTHON PROGRMMING

CHAPTER – 4 : IMPLEMENTATION
Step 01 :

Clearly define the rules and regulations that we need to implement in our program and break them
down into smaller, manageable components. Also we determine the structure and logic of our
program based on the defined rules, we considering the input requirements, desired output, and
intermediate steps that need to be taken.

Step 02:

By break downing the problem into functions or classes to encapsulate

different aspects of our program. This will help organize our code and make code and make it easier
to manage and debug.

Step 03:

Ensuring that our program validates user inputs to adhere to the specified rules and produce the
expected outputs. We can use techniques such as input validation, error handling, or exception
handling to handle invalid inputs gracefully.

Step 04:

Finally by debugging our program and refining the implementation if necessary. Test it again with
various inputs to verify its correctness and make any necessary adjustments.

Step 05:

Also providing clear and concise documentation to explain the purpose of the program, its
functionality, and the rules and regulations it follows. This will make it easier for others (or our future
self) to understand and maintain the code.

Step 06:

Remembering to adapt the steps to the specific rules and regulations we want to implement. The
process may vary depending on the complexity and nature of the rules involved.

9
COMPUTER SCIENCE DEPARTMENT
KEYLOGGER IN PYTHON PROGRMMING

Chapter-5 : program analysis

 This line imports the keyboard module from the pynput library, which provides
functionality to listen for and control keyboard events.

 This line sets the variable termination_key to the desired termination key. In this
example, it is set to keyboard.Key.f12, but you can change it to any key from the
keyboard.Key enum. This key will be used to stop the listener and terminate the

program .

 This line sets the variable termination_key to the desired termination key. In this
example, it is set to keyboard.Key.f12, but you can change it to any key from the
keyboard.Key enum. This key will be used to stop the listener and terminate the
program

 This is the callback function on_release, which is called whenever a key is released. It
checks if the released key is the termination key specified earlier. If it is, the function
returns False, which will stop the listener and terminate the program.

11
COMPUTER SCIENCE DEPARTMENT
KEYLOGGER IN PYTHON PROGRMMING

Chapter-5 : program analysis

 This block creates an instance of the keyboard.Listener class and sets the on_press and
on_release functions as callbacks. It then starts the listener by calling the join() method
on the listener instance. This method blocks the program's execution and waits for the
listener to finish. The listener will capture key events and invoke the appropriate
callback functions (on_press and on_release) when necessary

11
COMPUTER SCIENCE DEPARTMENT
KEYLOGGER IN PYTHON PROGRMMING

Chapter-6 : result and analysis

When we run the “ Keylogger” program in the Jupiter notebook Interpreter , we will
get following as a output.

It will start listening for keyboard events and capturing key presses. The program will
continue running until the termination key is released.

As the program captures key presses, it will write the corresponding character representation
of each pressed key to the "output.txt" file. The file will be created in the same directory as
the Python script if it doesn't exist, or it will be appended to if it already exists.

The output of the program will be the characters of the keys that were pressed and captured
during the runtime of the program. Each character will be appended to the "output.txt" file as
it is captured.For example, if you press the keys 'H', 'e', 'l', 'l', 'o', and then release the
termination key (e.g., F12), the "output.txt" file will contain the following content:

Here is an example about how the keylogger records the keys of the keyboard and saves it in
the output file.

What we are typing in the keyboard after we run the program Keylogger , everything will be
recorded in the “ output.txt “ file

As follow :

13
COMPUTER SCIENCE DEPARTMENT
KEYLOGGER IN PYTHON PROGRMMING

Chapter-6 : result and analysis

The program captures and writes the character representation of each key press to the file.
Keys without character representation, such as special keys or function keys, are ignored and
not written to the file.

Remember to check the file location and have the necessary write permissions in the
directory where the script is executed to ensure successful writing to the "output.txt" file.

However, in a Jupyter Notebook, the program might behave differently from running it in a
standalone Python script, primarily due to the interactive nature of the Jupyter environment.

It can also record the keystrokes that are used in any of the login websites and here is the
example how it works :

13
COMPUTER SCIENCE DEPARTMENT
KEYLOGGER IN PYTHON PROGRMMING

Chapter-6 : result and analysis

And whatever we typed in any any time in any of the sites including the incrypted password
it still records the keys as the password and user names are typed from the keyboard itself and
not by websites . So below is the example how the above entered username and encrypted
password saved in the file :

For instance :

 Notebook Kernel State: Jupyter Notebook runs code cells interactively, and the state of
the Python kernel might be different from what you expect. For example, if you

13
COMPUTER SCIENCE DEPARTMENT
KEYLOGGER IN PYTHON PROGRMMING

Chapter-6 : result and analysis


 interrupt the kernel or restart it, the keyboard listener may be disrupted, leading to
unexpected behavior

 Output Display: The program writes captured keys to the "output.txt" file, but since
it's a Jupyter Notebook, you won't see the content of the file directly in the output cell.
You would need to open the file separately or use Python code to read and display the
content of the file.

 Interrupting the Program: In a Jupyter Notebook, you can interrupt the program's
execution by interrupting the kernel or stopping the code cell. This will halt the program,
and it might not capture the termination key correctly.

Due to these differences, it's recommended to run the Keyboard Event Recorder
in a standalone Python script environment for more reliable and consistent results. If you
want to interactively test the program in Jupyter Notebook, consider running it in a separate
terminal window or console where the keyboard listener can function uninterrupted.

The program terminates by stopping the keyboard listener when the termination key is
released. Let's go through the steps to understand how exactly the program terminates:

1. The program starts by creating an instance of the keyboard.Listener class, which is


responsible for capturing and handling keyboard events.
2. The listener is set up with two callback functions: on_press(key) and on_release(key).
These functions will be triggered when a key is pressed and when a key is released,
respectively.
3. The on_release(key) callback function is defined to check if the released key is the
termination key (keyboard.Key.f12 by default, but it can be customized). If the released
key matches the termination key, the function returns False.
4. When the listener captures a key release event, it checks if the key is the termination key.
If it is, the on_release(key) function returns False.
5. Returning False from the on_release(key) function is a signal to the listener that it should
stop capturing keyboard events and terminate the program.
13
COMPUTER SCIENCE DEPARTMENT
KEYLOGGER IN PYTHON PROGRMMING

Chapter-6 : result and analysis


6. The listener, running in a separate thread, continuously monitors for keyboard events and
invokes the corresponding callback functions.
7. While the listener is capturing keyboard events, it is also checking for the termination
condition in the on_release(key) function.
8. As soon as the termination key is released, the on_release(key) function returns False,
signaling the listener to stop capturing events.
9. Once the listener receives the False signal from the on_release(key) function, it exits the
capturing loop and terminates itself.
10.The program continues to the next line after the listener.join() call,

which prints the message "Keyboard listener stopped."

In summary, the program terminates by stopping the keyboard listener when the termination
key is released. The on_release(key) function plays a critical role in detecting the termination
condition and sending a signal to the listener to stop capturing events. This design ensures
that the program runs efficiently and stops gracefully when the termination key is pressed,
providing a smooth user ex

13
COMPUTER SCIENCE DEPARTMENT
KEYLOGGER IN PYTHON PROGRMMING

Chapter-6 : result and analysis


In summary, the "Keyboard Event Recorder" offers a robust and user-friendly solution for
monitoring and recording keyboard events. Its versatility and potential benefits, coupled with a
responsible approach to usage, make it a valuable addition to any developer's toolkit. By
leveraging this tool responsibly, users can optimize their typing habits, enhance
productivity, and streamline various tasks through automated keyboard actions.

In conclusion, the "Keyboard Event Recorder" program provides a versatile solution for
capturing and recording keyboard events in Python. By utilizing the pynput library, the program
efficiently captures key presses and writes their corresponding character representations into an
output file. The ability to customize the termination key enhances user flexibility and control.

While the program offers valuable insights into keyboard usage patterns and potential
automation opportunities, users should be cautious about privacy and security concerns. Proper
handling of sensitive data and user consent are crucial to ensure the program's ethical usage.

Overall, the "Keyboard Event Recorder" is a powerful tool that finds applications in various
domains, such as productivity enhancement, debugging, testing, and security auditing. By adhering
to ethical guidelines and using it responsibly, users can harness its potential to improve their
workflow and gain valuable insights into keyboard interactions.

Furthermore, the "Keyboard Event Recorder" program presents an intuitive user


interface, guiding users on how to start and stop the keyboard listener effectively. The inclusion of
clear informational messages enhances the user experience and ensures smooth interaction with the
program.

The program's flexibility in choosing a termination key allows users to tailor it to


their specific needs and preferences. This adaptability makes it suitable for a wide range of
applications, from basic key logging to advanced automation scripts.Despite its utility, users must
exercise caution when using the "Keyboard Event Recorder." It is essential to be mindful of
potential privacy implications and the responsible handling of recorded data. By respecting ethical
considerations and legal obligations, users can ensure the program's proper usage while avoiding
any unintended consequences.

13
COMPUTER SCIENCE DEPARTMENT
KEYLOGGER IN PYTHON PROGRMMING

Chapter-6 : result and analysis

13
COMPUTER SCIENCE DEPARTMENT
KEYLOGGER IN PYTHON PROGRAMMING

BIBILOGRAPHY

 ChatGPT

Publisher : chat.openi.com
https://openai.com/chatgpt
 GeeksforGeeks
Publisher : Ventura Publisher
GeeksforGeeks | A computer science portal for geeks
 GitHub
Publisher : Microsoft

Github : Let’s build from here.Github

19
COMPUTER SCIENCE DEPARTMENT

You might also like