1
00:00:00,330 --> 00:00:01,080
Welcome back.

2
00:00:01,080 --> 00:00:05,390
Let's start out key logger already created the project in my PI charm.

3
00:00:05,670 --> 00:00:06,630
So you should do the same.

4
00:00:06,810 --> 00:00:11,700
And after you do that go into the new and create new python file.

5
00:00:11,700 --> 00:00:18,080
We can call it simply key logger that Pete Y right at the beginning.

6
00:00:18,100 --> 00:00:21,580
There are two libraries that we are going to need in order to complete this program.

7
00:00:21,580 --> 00:00:26,150
One of them is a standard library that comes with python which is the OS library.

8
00:00:26,260 --> 00:00:31,540
And the second one is a library that will allow us to automate the process of capture and keystrokes

9
00:00:32,410 --> 00:00:34,660
and that library is called by input.

10
00:00:34,660 --> 00:00:42,750
So we are going to import it right here from by input dot keyboard.

11
00:00:43,180 --> 00:00:47,810
We want to import a listener which will listen for our keystrokes.

12
00:00:47,920 --> 00:00:51,190
Now right away we can notice that this library does not exist.

13
00:00:51,310 --> 00:00:58,640
Therefore open up your terminal and Pip 3 install by input.

14
00:00:58,680 --> 00:01:03,960
Now one more thing is that our key logger can be both used for Windows and Linux.

15
00:01:03,960 --> 00:01:09,060
First of all we are going to test it in Linux environment and then right after it we are going to transfer

16
00:01:09,060 --> 00:01:12,360
it to Windows compile it and then test it there as well.

17
00:01:12,620 --> 00:01:13,030
OK.

18
00:01:13,590 --> 00:01:15,140
So let's close this.

19
00:01:15,210 --> 00:01:20,730
Now that we've got the library installed inside of our virtual environment we will start off right away

20
00:01:20,790 --> 00:01:26,160
with creating of our listener object that will allow us to capture keystrokes and you actually created

21
00:01:26,190 --> 00:01:34,230
similar as you open a file so you use the with command but instead of with open you type here with the

22
00:01:34,230 --> 00:01:34,650
listener

23
00:01:37,800 --> 00:01:43,670
and in the brackets you specify the actual function that you want to execute while the listener is running

24
00:01:43,680 --> 00:01:46,140
so we're going to call that function on press

25
00:01:49,560 --> 00:01:56,920
and we're going to call the object listener then what we want to do throughout our entire program is

26
00:01:56,920 --> 00:02:00,750
type here listener dot join.

27
00:02:01,300 --> 00:02:02,840
This will start our listener.

28
00:02:02,920 --> 00:02:09,080
And now what we are left to do is code our own press function and our own press function should do it.

29
00:02:09,120 --> 00:02:14,650
It should actually store all the keystrokes that the target inputs inside of a file that we're going

30
00:02:14,650 --> 00:02:15,940
to create.

31
00:02:15,940 --> 00:02:21,010
Now we also want to make sure that we hide that files so that the target cannot find it on their machine.

32
00:02:21,310 --> 00:02:21,780
All right.

33
00:02:21,820 --> 00:02:25,690
So let's start off with the press function.

34
00:02:25,690 --> 00:02:27,150
We first of all need to define it.

35
00:02:27,160 --> 00:02:33,940
So def on press and this function of course has to take an input of keystrokes soils and to just type

36
00:02:33,940 --> 00:02:34,510
it short.

37
00:02:34,510 --> 00:02:42,970
Right here key this is each character that the target for input will represent this key and for this

38
00:02:42,970 --> 00:02:46,990
function we are going to need two global variables which we are going to create right at the beginning

39
00:02:46,990 --> 00:02:48,020
of the program.

40
00:02:48,040 --> 00:02:51,970
One of them is going to be a list and it will be called the keys.

41
00:02:52,090 --> 00:02:58,600
So this Key's list will store multiple keys at the same time and store them one by one inside of a file

42
00:02:59,050 --> 00:03:04,030
and we will also need a variable called count and you will see in just a second why we need to count

43
00:03:04,030 --> 00:03:04,760
variable.

44
00:03:04,870 --> 00:03:09,730
Make sure that you set it to 0 and the Keys list will be empty for now.

45
00:03:09,730 --> 00:03:14,300
One more thing that we need to do inside of our own press function before recorded.

46
00:03:14,350 --> 00:03:23,540
We need to make sure that we call the global variables which are keys and count so global keys com account

47
00:03:23,900 --> 00:03:26,350
will refer to the python that we are using.

48
00:03:26,360 --> 00:03:30,770
These two variables and not local variables inside of this function.

49
00:03:30,850 --> 00:03:31,820
Okay.

50
00:03:32,300 --> 00:03:36,470
Right away first thing that we want to do since our listener is started.

51
00:03:36,470 --> 00:03:41,450
And if we get to this function that means that the key has already been input to the inside of a keyboard

52
00:03:41,480 --> 00:03:42,890
and has to be processed.

53
00:03:43,010 --> 00:03:49,310
Therefore we will straight up add that key to the Keys list so keys not append Append is a function

54
00:03:49,310 --> 00:03:55,340
that allows us to add elements to the list and we want to spend the key element or the character that

55
00:03:55,340 --> 00:04:01,910
was input it inside of a keyboard after it for each character we want to increase the count variable

56
00:04:02,630 --> 00:04:03,260
by 1.

57
00:04:03,350 --> 00:04:09,620
And we do that by specifying count plus equals 1 and after this we want to store this key inside of

58
00:04:09,620 --> 00:04:12,510
a file that will store all keystrokes.

59
00:04:12,650 --> 00:04:18,950
Well how we can know if a key has been input it well if the count variable is not zero that means the

60
00:04:18,950 --> 00:04:27,080
key has been input and therefore we're going to check if count is bigger or equal to 1

61
00:04:30,240 --> 00:04:36,750
we will straightaway set the count back to 0 and then we can create a function which will be called

62
00:04:36,840 --> 00:04:42,930
right file and we will write keys to the file and also write after it.

63
00:04:42,930 --> 00:04:49,740
We want to make sure that we add keys to be equal to an empty list and just so you can understand this.

64
00:04:49,740 --> 00:04:55,230
The reason why we're adding keys to be an empty list right to have to rewrite them to the file is because

65
00:04:55,320 --> 00:04:58,110
we don't want to write the same things twice.

66
00:04:58,110 --> 00:05:03,380
So for example let's say the target input something in the keyboard we go to process this key.

67
00:05:03,570 --> 00:05:09,410
We append the actual key or the character inside of the keys list we increase the count by 1.

68
00:05:09,480 --> 00:05:16,320
Then we write those keys to the actual file and if we don't clear the keys list next time that the target

69
00:05:16,380 --> 00:05:22,550
input something they will also write the first thing as well as the second thing that they typed in.

70
00:05:22,920 --> 00:05:29,550
So we will have everything doubled up and if they've righted the third time the first two things will

71
00:05:29,550 --> 00:05:30,660
be tripled up.

72
00:05:30,690 --> 00:05:36,500
Therefore we're just going to store unnecessary information or unnecessary keys multiple times.

73
00:05:36,600 --> 00:05:39,060
So that is why we set the count to be equal to zero.

74
00:05:39,150 --> 00:05:40,890
And keys to be empty.

75
00:05:40,890 --> 00:05:41,180
Right.

76
00:05:41,180 --> 00:05:42,890
I have to rewrite it to the file.

77
00:05:43,380 --> 00:05:44,650
OK.

78
00:05:44,950 --> 00:05:50,890
Now this is the entire on press function and in the next video we're going to see how we can write them

79
00:05:50,890 --> 00:05:56,160
to the file and we'll also see how we can write some of the special characters that cannot be printed

80
00:05:56,370 --> 00:05:57,020
in a file.

81
00:05:57,930 --> 00:05:58,240
Okay.

82
00:05:58,270 --> 00:06:02,430
So thank you for watching this tutorial and I will see you in the next lecture where we're going to

83
00:06:02,430 --> 00:06:04,730
code our right file function.

84
00:06:04,890 --> 00:06:05,600
Take care.

85
00:06:05,610 --> 00:06:05,900
Bye.
