kEYLOGGER - Project - Report - Final Copy1
kEYLOGGER - Project - Report - Final Copy1
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
1
COMPUTER SCIENCE DEPARTMENT
GOVERNMENT ENGINEERING COLLEGE
B.M ROAD RAMANAGARA-562159
Affiliated to VTU Belagavi, Approved by AICTE-New Delhi
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).
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:
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:
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.
Set the callback functions for key press and release events
9.Program terminates
6
COMPUTER SCIENCE DEPARTMENT
CHAP CHAPTER-1: INTRODUCTION TER-1:
7
COMPUTER SCIENCE DEPARTMENT
KEYLOGGER IN PYTHON PROGRMMING
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
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:
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
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
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
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
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
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
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:
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
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.
13
COMPUTER SCIENCE DEPARTMENT
KEYLOGGER IN PYTHON PROGRMMING
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
19
COMPUTER SCIENCE DEPARTMENT