Okay.
The program is, uh, almost complete.
But still, there is something we need to add.
Um, if you're using OOP and that is a constructor, you may ask what is a constructor?
Okay.
Constructor is like main function on Java if you are moving from Java to Python.
If not these uh, constructor method is the main method.
Whenever we are creating the object from these class of key logger, the first thing which is going
to be executed is the main function or this constructor.
So how can we create constructor in Python.
Let's do that okay.
We define it okay.
Use two and two underscore here.
And then we call it init something like this.
But let me remove some of them from here.
Okay.
This part.
And inside here, if you define anything.
Okay.
If you add anything that will be added to the class.
For example, here we are going to move the log keyword.
Global keyword.
We'll go global uh variable into uh this one into this um init method which is the constructor.
Now we can use it here.
Okay.
But not just the log we need to use self dot log is equal to nothing.
Okay.
So now this is okay.
Okay.
And also I'm going to create another method here.
Okay I am going to name it append uh to.
Log Lock.
Okay, so we give the cell here and right here because we are appending something to the log.
So we need to add another variable here.
Okay.
Another argument.
And that is going to be for example a string variable.
And here inside this we use self dot log is equal to self dot log plus string.
Okay.
Now by doing this you know what.
What that what this means okay.
Because we are concatenating these two and we are adding that to the log variable okay.
Okay.
And here this method is okay.
And after this time we don't need the global variable because we have a method called append two.
And we need to add something else here okay.
Uh, let's remove everything from here.
And down here, I need to add something called.
Let's create another variable.
I'm going to name it current.
Um, current key.
Okay.
So this current key is equal to s t r key dot c h a r.
Okay.
Now we have this here.
And also in here we have.
If key is equal to key dot space then we need to add a space instead of key dot space okay.
So here we don't need to use this kind of log and something like this.
We just need to add that current key to.
Current key which is equal to something like this okay.
Okay.
So and also we have the else part in else part.
We need to add this all here.
Okay.
So here we are going to tell that this current key is equal to current.
Key is equal to space okay.
Plus this key and then plus space.
So this is the last thing we need to do.
And also we need to uh we need to use uh append to log method here.
We need to call this function here.
And that is going to be in here.
So we use self dot append to log okay.
And we are adding the current key.
Now each time we execute the program and we press any key that will add the first key here to the log,
and then try to add it into this current key.
Okay.
And each time it is adding a new key we are pressing.
And at the end you see that this append method is doing the concatenation here.
So.
Okay.
And also in report report again you see we have a global log here.
Okay.
That's something we need to remove it from here.
Okay.
So we don't need this.
And instead of having only log we use self dot log.
And also we have the log here we need to use self dot log which is equal to nothing.
Okay.
So.
Now let's go and do a quick test again.
Let me clear this.
Okay.
Python in logger.
Py hit enter.
Now, for example, I am saying this is a test.
See?
Now it is going to print s t here.
Okay.
And again I'm going to this is another, uh test.
So now you see this is another th.
And here we are going to have a backspace and then s t and something like.
So now this program is almost completed.
Almost not really completed but almost completed.
Here you see we are printing the log.
Okay.
Now instead of printing this we need to send this to an email.
So let's go and do that.