Okay.
In the previous lecture, we created this simple keylogger that is capturing only the keys that we were
pressing.
And here, as you see that while we are pressing each key, it is showing me that key in one new line.
We want to send this into an email or into a server, or even writing into a file.
We need to here, as you see.
For example, if you're pressing 100 keys so it will send 100 emails to a person or the email you're
providing.
So.
The best solution for this is to have a global variable here okay.
So while we are having a global variable we can add or we can concatenate each keys that is adding or
that that the user or the victim is entering.
So for that we need to use let's create a variable.
Name it log.
It is equal to an empty string right now.
Okay, so we have this empty.
This empty string is here.
Now we have the key here.
Okay.
Each time that person is entering the key, we need to add this into the lock.
So very easy.
Log is equal to log plus key.
And you may know or may not know that this key is not a string.
It is an object okay.
Object type of key.
So we need to change this to a string.
So very good.
STR.
STR finished.
And now let's print the log.
And let's see how does it looks like.
Okay.
Oops.
Use Ctrl c.
Let's clear this.
Okay.
Can't open file.
No such file or directory.
What do you mean you don't?
We have in here Python key logger.
Oops.
This again.
Let me use RLS.
We have this okay.
Python key logger.py hit enter.
So right now it is waiting to write something.
Let's here write r.
And you see again it is giving me an error.
And that is log is equal to.
This cannot access local variable log where it is not associated with a value.
Okay.
Beautiful.
You see we are having log here which is out of this function.
And we are using it inside the function.
We need to use something called global variable okay.
We need to use global and then global keyword and then name of this uh, variable.
Okay.
So.
Here let me use once again execute this and let's, uh, hit backspace and then write R again.
R again.
R backspace.
Let's write hello world.
Hit enter.
And here right now you see that we have backspace okay.
We have three R.
We have backspace backspace backspace backspace.
We have hello space world key enter.
So now if we want to send this to an email.
So we will be sending all these into an email.
And right now it is more readable okay.
Or if you want to write this into a text file we will be opening a txt file.
And we can write this into a file okay.
We will be improving this in the next lecture.
So let's go and see that.