WEBVTT

00:00.560 --> 00:00.920
Okay.

00:00.960 --> 00:04.280
The program is, uh, almost complete.

00:04.440 --> 00:07.560
But still, there is something we need to add.

00:07.920 --> 00:16.320
Um, if you're using OOP and that is a constructor, you may ask what is a constructor?

00:16.360 --> 00:16.600
Okay.

00:16.640 --> 00:24.680
Constructor is like main function on Java if you are moving from Java to Python.

00:24.840 --> 00:30.400
If not these uh, constructor method is the main method.

00:30.400 --> 00:38.120
Whenever we are creating the object from these class of key logger, the first thing which is going

00:38.120 --> 00:42.840
to be executed is the main function or this constructor.

00:42.880 --> 00:45.760
So how can we create constructor in Python.

00:45.880 --> 00:47.480
Let's do that okay.

00:47.520 --> 00:48.920
We define it okay.

00:48.960 --> 00:51.960
Use two and two underscore here.

00:52.160 --> 00:55.720
And then we call it init something like this.

00:56.120 --> 00:58.800
But let me remove some of them from here.

01:02.240 --> 01:02.560
Okay.

01:02.600 --> 01:03.440
This part.

01:04.600 --> 01:08.200
And inside here, if you define anything.

01:08.320 --> 01:08.720
Okay.

01:08.840 --> 01:14.000
If you add anything that will be added to the class.

01:15.040 --> 01:19.600
For example, here we are going to move the log keyword.

01:19.640 --> 01:20.760
Global keyword.

01:20.920 --> 01:34.120
We'll go global uh variable into uh this one into this um init method which is the constructor.

01:34.160 --> 01:35.600
Now we can use it here.

01:35.640 --> 01:36.480
Okay.

01:36.480 --> 01:42.360
But not just the log we need to use self dot log is equal to nothing.

01:42.400 --> 01:43.080
Okay.

01:43.120 --> 01:45.480
So now this is okay.

01:45.520 --> 01:46.600
Okay.

01:46.640 --> 01:49.760
And also I'm going to create another method here.

01:50.160 --> 01:56.000
Okay I am going to name it append uh to.

01:58.160 --> 01:58.750
Log Lock.

01:59.110 --> 02:08.110
Okay, so we give the cell here and right here because we are appending something to the log.

02:08.510 --> 02:10.510
So we need to add another variable here.

02:10.550 --> 02:10.670
Okay.

02:10.710 --> 02:11.510
Another argument.

02:11.510 --> 02:14.150
And that is going to be for example a string variable.

02:14.830 --> 02:26.710
And here inside this we use self dot log is equal to self dot log plus string.

02:26.750 --> 02:27.110
Okay.

02:27.630 --> 02:29.230
Now by doing this you know what.

02:29.590 --> 02:31.990
What that what this means okay.

02:31.990 --> 02:38.430
Because we are concatenating these two and we are adding that to the log variable okay.

02:40.550 --> 02:41.710
Okay.

02:41.750 --> 02:44.430
And here this method is okay.

02:44.830 --> 02:51.550
And after this time we don't need the global variable because we have a method called append two.

02:52.350 --> 02:57.470
And we need to add something else here okay.

02:57.830 --> 03:01.030
Uh, let's remove everything from here.

03:02.150 --> 03:06.470
And down here, I need to add something called.

03:06.710 --> 03:08.150
Let's create another variable.

03:08.150 --> 03:10.430
I'm going to name it current.

03:10.470 --> 03:11.710
Um, current key.

03:11.750 --> 03:12.430
Okay.

03:12.470 --> 03:21.110
So this current key is equal to s t r key dot c h a r.

03:21.150 --> 03:21.510
Okay.

03:21.750 --> 03:23.590
Now we have this here.

03:25.830 --> 03:28.270
And also in here we have.

03:28.750 --> 03:35.510
If key is equal to key dot space then we need to add a space instead of key dot space okay.

03:37.070 --> 03:41.550
So here we don't need to use this kind of log and something like this.

03:41.670 --> 03:47.430
We just need to add that current key to.

03:49.870 --> 03:53.790
Current key which is equal to something like this okay.

03:56.030 --> 03:56.430
Okay.

03:58.710 --> 04:02.870
So and also we have the else part in else part.

04:02.910 --> 04:06.790
We need to add this all here.

04:06.830 --> 04:07.790
Okay.

04:07.790 --> 04:15.310
So here we are going to tell that this current key is equal to current.

04:15.350 --> 04:18.630
Key is equal to space okay.

04:19.430 --> 04:22.990
Plus this key and then plus space.

04:23.710 --> 04:27.350
So this is the last thing we need to do.

04:27.350 --> 04:36.870
And also we need to uh we need to use uh append to log method here.

04:36.870 --> 04:38.790
We need to call this function here.

04:39.750 --> 04:42.270
And that is going to be in here.

04:42.270 --> 04:47.790
So we use self dot append to log okay.

04:47.790 --> 04:50.950
And we are adding the current key.

04:50.990 --> 05:00.710
Now each time we execute the program and we press any key that will add the first key here to the log,

05:00.710 --> 05:03.790
and then try to add it into this current key.

05:03.830 --> 05:04.150
Okay.

05:04.150 --> 05:07.230
And each time it is adding a new key we are pressing.

05:07.270 --> 05:13.270
And at the end you see that this append method is doing the concatenation here.

05:13.870 --> 05:14.190
So.

05:16.350 --> 05:16.790
Okay.

05:16.830 --> 05:23.510
And also in report report again you see we have a global log here.

05:23.550 --> 05:24.590
Okay.

05:24.630 --> 05:28.390
That's something we need to remove it from here.

05:28.510 --> 05:29.550
Okay.

05:29.550 --> 05:31.030
So we don't need this.

05:33.030 --> 05:38.910
And instead of having only log we use self dot log.

05:39.710 --> 05:46.710
And also we have the log here we need to use self dot log which is equal to nothing.

05:46.750 --> 05:47.150
Okay.

05:48.150 --> 05:48.510
So.

05:50.950 --> 05:53.750
Now let's go and do a quick test again.

05:58.540 --> 05:59.980
Let me clear this.

06:02.420 --> 06:02.820
Okay.

06:02.860 --> 06:04.180
Python in logger.

06:04.460 --> 06:05.700
Py hit enter.

06:06.500 --> 06:11.140
Now, for example, I am saying this is a test.

06:12.140 --> 06:13.380
See?

06:13.420 --> 06:16.540
Now it is going to print s t here.

06:16.780 --> 06:17.220
Okay.

06:17.700 --> 06:24.180
And again I'm going to this is another, uh test.

06:24.660 --> 06:27.700
So now you see this is another th.

06:27.940 --> 06:33.820
And here we are going to have a backspace and then s t and something like.

06:33.860 --> 06:36.980
So now this program is almost completed.

06:37.180 --> 06:41.380
Almost not really completed but almost completed.

06:41.700 --> 06:45.180
Here you see we are printing the log.

06:45.220 --> 06:45.860
Okay.

06:45.900 --> 06:49.940
Now instead of printing this we need to send this to an email.

06:50.660 --> 06:52.700
So let's go and do that.
