1 00:00:00,270 --> 00:00:04,950 Hello everybody and welcome back to the second tutorial of our kg. 2 00:00:05,280 --> 00:00:11,760 And in the previous tutorial we coded this little program right here which is key logger not a wonder 3 00:00:11,780 --> 00:00:17,590 pie which actually adds the keystrokes to be file called key logger on the extreme. 4 00:00:17,760 --> 00:00:24,120 But we noticed once we actually run the file so let's run it key logger won the pie and we just type 5 00:00:24,120 --> 00:00:30,300 your hello world and we call the program if we catch the key logger that the file that we received from 6 00:00:30,300 --> 00:00:36,960 it it actually prints out these weird letters right here with these apostrophes between each letter 7 00:00:37,200 --> 00:00:39,760 and with these you will between each letter. 8 00:00:39,810 --> 00:00:43,620 So what we want to do is actually get rid of that and how will we do that. 9 00:00:43,620 --> 00:00:52,060 Well let us actually make another program that's called a key logger to the PI and let's actually make 10 00:00:52,060 --> 00:00:54,880 first eat the import. 11 00:00:54,880 --> 00:01:02,380 So import key pi and put the keyboard I believe should be something like this. 12 00:01:03,100 --> 00:01:04,840 Let's start off with the same thing. 13 00:01:04,840 --> 00:01:12,800 So same as the previous keyboard underscore listener key equals pi input not keyboard not listener. 14 00:01:13,480 --> 00:01:23,340 And we want to use the on press function with the two hour process keys Ross's keys. 15 00:01:23,650 --> 00:01:27,930 Then we use the same as before so with keyboard underscore listener. 16 00:01:28,150 --> 00:01:35,890 We actually keyboard underscore listener and the join and right now since we set up our listener right 17 00:01:35,920 --> 00:01:42,630 now we need to write a function that will actually get rid of the process. 18 00:01:42,760 --> 00:01:44,340 I don't need to see right here. 19 00:01:44,350 --> 00:01:52,270 So let me just delete one process on the score keys and we implement key in that function. 20 00:01:52,360 --> 00:02:01,180 And right now what we want to actually do is we want to try and actually print the letters first. 21 00:02:01,190 --> 00:02:03,590 Without those apostrophes. 22 00:02:03,710 --> 00:02:04,880 So how we would do that. 23 00:02:04,880 --> 00:02:11,000 We can actually do that with using the key itself and basically making the chart. 24 00:02:11,150 --> 00:02:15,890 Now there is a simple thing in Python that we can use which is key the chart to do that. 25 00:02:15,890 --> 00:02:19,680 So let us see how that look like. 26 00:02:20,410 --> 00:02:28,810 So let us create a variable called for example keys and let's actually add nothing to it then use the 27 00:02:28,810 --> 00:02:34,330 same variable which is global Keys where we will actually store the keys itself. 28 00:02:34,330 --> 00:02:37,490 So let us try to just type your keys. 29 00:02:37,600 --> 00:02:48,260 Equal keys lost the string of key dot char now before the previous video we basically did something 30 00:02:48,260 --> 00:02:54,920 similar just we didn't have this dot Charlot right here and all we want to do right now I know that. 31 00:02:54,920 --> 00:03:01,130 Check this out is actually print keys so let's see what this will do. 32 00:03:01,200 --> 00:03:09,550 It will process the key to our function then since our keys is nothing it will add to our variable keys 33 00:03:09,610 --> 00:03:14,440 it will add the string of the key dot char then it will print the keys. 34 00:03:14,440 --> 00:03:19,060 Now this will print the keys forever as long as we are running this program and typing something in 35 00:03:19,060 --> 00:03:20,350 the keyboard. 36 00:03:20,350 --> 00:03:22,060 So let us control all this. 37 00:03:22,080 --> 00:03:30,330 No control excel at this front the key logger just make it an executable key logger to the PI. 38 00:03:31,090 --> 00:03:36,330 And if we run it whoops we just closed this. 39 00:03:36,340 --> 00:03:46,300 If we run it once again and type your hello world you will see that it will stop the word hello first 40 00:03:46,690 --> 00:03:51,710 and then we will get an error called attribute error. 41 00:03:51,730 --> 00:03:57,730 Now the reason why we got this attribute error is because our program worked perfectly while we were 42 00:03:57,730 --> 00:04:05,800 typing the letters but as soon as I went to actually type the spacebar it said key object has no attribute 43 00:04:05,830 --> 00:04:14,120 char since the spacebar key actually doesn't have any character that actually represents it and that's 44 00:04:14,120 --> 00:04:15,490 why we get this error. 45 00:04:15,500 --> 00:04:22,560 So let me show you once again see all around key logger the PI and just up here Shell lo and then case 46 00:04:22,880 --> 00:04:25,800 we once again get the same error. 47 00:04:25,860 --> 00:04:32,010 So what we want to do right now is actually implement try and accept function that will actually use 48 00:04:32,010 --> 00:04:33,470 this arrow as an accept. 49 00:04:33,470 --> 00:04:41,190 So we want to cope with this error since this is the error to get for every left for every basically 50 00:04:41,200 --> 00:04:46,170 key that we type in such a space bar delete backspace enter and so on. 51 00:04:46,260 --> 00:04:50,700 All of those keys that actually do not have a character representation. 52 00:04:50,700 --> 00:04:54,590 So we want to actually implement that in our key logger as well. 53 00:04:55,260 --> 00:05:00,660 But what is good about our second key logger is that you saw that we do not have the weird apostrophe 54 00:05:00,660 --> 00:05:02,180 between each letter anymore. 55 00:05:02,310 --> 00:05:10,070 We just get the basic output of the string itself now we also need a little bit more work on this so 56 00:05:10,070 --> 00:05:14,060 don't worry this is not the ending projects. 57 00:05:14,180 --> 00:05:21,380 Let us before we do that Randi try so we will try to actually add this the character version of the 58 00:05:21,380 --> 00:05:24,170 key to our variable keys. 59 00:05:24,350 --> 00:05:29,720 And in case that doesn't work that means that the character or the key that we typed in doesn't really 60 00:05:29,720 --> 00:05:31,900 have the character representation. 61 00:05:31,910 --> 00:05:37,480 So we want to use except and then the error that we copied which is attribute error. 62 00:05:38,330 --> 00:05:40,630 And then we have to press two dots. 63 00:05:40,670 --> 00:05:43,940 And what we want to do is basically 64 00:05:47,410 --> 00:05:50,650 run and if l statement right here. 65 00:05:50,650 --> 00:05:54,750 So for example we know that in our previous video. 66 00:05:55,150 --> 00:06:01,470 Let me just save this and leave it like this for now just to show you if I copy the key logger dot to 67 00:06:01,540 --> 00:06:09,460 steal from our previous video you can see that once this press space it actually prints key dot space 68 00:06:10,270 --> 00:06:17,650 so we can use this for example to process the key and add if key equals key dot space then we will add 69 00:06:17,650 --> 00:06:20,130 something to the Keys variable. 70 00:06:20,350 --> 00:06:23,140 So let us see what they actually mean by that. 71 00:06:23,140 --> 00:06:27,580 So let us go back to our key logger to the PI and if I just type here 72 00:06:30,350 --> 00:06:40,220 if key equals equals key dot space which is what prints out a one in our previous tutorial once we actually 73 00:06:40,220 --> 00:06:41,460 type spacebar. 74 00:06:42,550 --> 00:06:48,050 Well let's see what we can actually add to our keys variable. 75 00:06:48,230 --> 00:06:50,000 So keys would be 76 00:06:52,730 --> 00:07:00,020 Bob's everything previously so keys and then plus what the best thing for students Barry's is basically 77 00:07:00,020 --> 00:07:01,120 just an empty space. 78 00:07:01,130 --> 00:07:05,040 So make sure type double quotes and an empty space and then another double quotes. 79 00:07:05,060 --> 00:07:08,990 So this will add an actual space bar between every 80 00:07:11,710 --> 00:07:16,980 every time we actually print space so let us see how this will work. 81 00:07:17,090 --> 00:07:19,440 Let us save this. 82 00:07:19,510 --> 00:07:21,390 Now let's just run it once again. 83 00:07:21,390 --> 00:07:22,850 So how low. 84 00:07:22,940 --> 00:07:29,380 And if I just type your space and type your world you can see it prints out hello world right here. 85 00:07:29,400 --> 00:07:32,430 We didn't get the error or no character for space. 86 00:07:32,460 --> 00:07:35,740 It only printed the empty spot right here. 87 00:07:35,970 --> 00:07:42,840 But we also need to do the same for every other character that doesn't have the implementation of or 88 00:07:42,840 --> 00:07:45,600 basically the representation in character wise. 89 00:07:45,720 --> 00:07:46,410 So right. 90 00:07:46,410 --> 00:07:52,720 We want what we want to do right here is for now on just type here else for any other character that 91 00:07:52,720 --> 00:07:56,740 doesn't have the string key char we want to type your keys. 92 00:07:56,760 --> 00:08:05,250 Equal keys plus and then empty space so we can actually make distance between the regular characters 93 00:08:05,270 --> 00:08:12,000 and for example and enter a backspace to delete a tab and shift or and so on and we want to add the 94 00:08:12,000 --> 00:08:14,720 string of that key. 95 00:08:15,060 --> 00:08:21,750 Now as I said before we are here using only the key and not key the char since if we actually specify 96 00:08:21,750 --> 00:08:27,270 the key to char we would get the error once again you know you want to specify only the string of the 97 00:08:27,270 --> 00:08:34,400 key for every every basically Batman or keyboard that doesn't have the character representation. 98 00:08:34,410 --> 00:08:39,990 So and after that we also want to add an empty space so we can actually differentiate them. 99 00:08:40,020 --> 00:08:42,750 Let's save this and see how this will actually work. 100 00:08:43,050 --> 00:08:55,050 So if a control X two exits key logger to that pi if I just type here Hello World and the key tab shift 101 00:08:55,890 --> 00:09:03,780 backspace you can see it prints all of these right here so what we want to do is actually add even for 102 00:09:03,780 --> 00:09:05,010 these other things. 103 00:09:05,040 --> 00:09:06,150 We want to add. 104 00:09:07,020 --> 00:09:12,880 Basically the representation and characters for all of them. 105 00:09:13,010 --> 00:09:19,100 Now for shift we can actually we can actually make the enter to be a new line. 106 00:09:19,100 --> 00:09:26,390 We can make the key step to be an empty space as well backspace could delete but we can also make that 107 00:09:26,510 --> 00:09:32,000 an empty space as well or we can just leave it like this so we know what the user has type so key enter 108 00:09:32,240 --> 00:09:36,140 basically means the use of type enter tab means tab and so on. 109 00:09:36,870 --> 00:09:42,440 Well let me just close this program right here and that will be about it for this tutorial. 110 00:09:42,440 --> 00:09:48,050 We will continue actually making our key logger better in the next tutorial and then we will actually 111 00:09:48,050 --> 00:09:51,290 implemented in our back door. 112 00:09:51,280 --> 00:09:55,400 So hope you enjoyed this video and I hope I see you in the next one by.