1 00:00:00,390 --> 00:00:07,600 Hello everybody and welcome back to the third part of the Q blogger tutorial making right now. 2 00:00:07,600 --> 00:00:12,490 What we want to actually do is you might have noticed that once we actually run our key logger to the 3 00:00:12,490 --> 00:00:17,320 pipe and we type something in it actually prints out as we type. 4 00:00:17,620 --> 00:00:26,350 Now for example if we do not want to get these printed out as we type we actually want to either print 5 00:00:26,350 --> 00:00:33,220 this every 20 seconds 30 seconds or we actually want to write this to a file at any certain period of 6 00:00:33,220 --> 00:00:33,910 time. 7 00:00:33,910 --> 00:00:38,440 So first of all let us see how we can print this every five seconds as well. 8 00:00:38,680 --> 00:00:41,690 So let us now know our key logger to that pi. 9 00:00:41,790 --> 00:00:49,420 Now let us set a function that will actually print this every 10 seconds for example so we type in our 10 00:00:49,420 --> 00:00:55,270 keyboard and every 10 seconds in our terminal we will get printed out everything that we have typed 11 00:00:55,270 --> 00:00:56,110 in our keyboard. 12 00:00:56,530 --> 00:01:07,630 So in order to do that let us make a function called for example the fine print we do not specify anything 13 00:01:07,660 --> 00:01:10,980 in that function since we actually don't need to. 14 00:01:11,010 --> 00:01:17,290 And once we want to use is the global variable that we use so global variable keys which is this variable 15 00:01:17,290 --> 00:01:24,500 right here and all we want to do right here is print he's loops keys. 16 00:01:24,730 --> 00:01:32,500 Now basically what this will do is if we call it it will basically perform the same as the in the previous 17 00:01:32,500 --> 00:01:33,410 tutorial. 18 00:01:33,430 --> 00:01:39,730 Now in order for us to actually make it run every 10 seconds we need to import the library which we 19 00:01:39,730 --> 00:01:43,390 use for the first time or now which is called threading. 20 00:01:43,570 --> 00:01:50,960 So just go up here and below your PI and put keyboard import threading. 21 00:01:51,150 --> 00:01:57,070 Now basically we're threading allows us is in this case to use a function called timer which will actually 22 00:01:57,070 --> 00:02:03,130 perform the function to specify in the brackets every certain period of time that we also specify in 23 00:02:03,130 --> 00:02:04,080 the brackets. 24 00:02:04,120 --> 00:02:07,570 So let us see what I actually mean. 25 00:02:07,570 --> 00:02:15,300 So we print the keys we print our current state of the keys we then want to set the keys to be nothing. 26 00:02:15,670 --> 00:02:20,090 Since we do know we do not want to print every time everything that we type. 27 00:02:20,110 --> 00:02:25,350 For example if we type Kelo world in the first 10 seconds we do not want to type this. 28 00:02:25,420 --> 00:02:31,580 We do not want to get the word prompted in the second to 10 seconds as well. 29 00:02:31,630 --> 00:02:37,390 Now I will show you what I mean in a second but before we do that let's set a variable called timer 30 00:02:37,660 --> 00:02:44,770 on which we will use to actually use our threading library and actually use our print function in order 31 00:02:44,770 --> 00:02:47,520 to make it run every 10 seconds. 32 00:02:48,940 --> 00:02:56,950 So timer equals and now we use this syntax right here so threading that timer and then here in the brackets 33 00:02:56,980 --> 00:03:02,680 we need to specify two things which function we want to use and at how much period of time we want to 34 00:03:02,680 --> 00:03:03,160 run it. 35 00:03:03,400 --> 00:03:09,130 So we want to run every 10 seconds then press comma and then we which function we want to use we want 36 00:03:09,130 --> 00:03:10,680 to use the print function. 37 00:03:10,690 --> 00:03:16,540 So basically what this means is as I said it will run the print function every 10 seconds and while 38 00:03:16,540 --> 00:03:20,050 the print function does is it just brings the keys. 39 00:03:20,140 --> 00:03:25,490 So all we have to do right now is type your timer not start. 40 00:03:25,720 --> 00:03:32,740 And we also in order for this all of this to work what we call that right here we want to actually call 41 00:03:32,740 --> 00:03:34,590 the print function somewhere. 42 00:03:34,630 --> 00:03:39,760 Now we will call the print function in our would keep our listener and write after it. 43 00:03:39,760 --> 00:03:47,090 We want to call a print function right here what this will do is to call the print function. 44 00:03:47,090 --> 00:03:48,830 It will go right here. 45 00:03:48,830 --> 00:03:55,520 Then this will start the timer which is trending which allows us basically this threading right here 46 00:03:55,520 --> 00:04:01,400 in this library that here allows us to run the action while the rest of the code is running itself. 47 00:04:01,640 --> 00:04:06,830 So what this does it creates a separate thread for this function which will run every 10 seconds and 48 00:04:06,890 --> 00:04:13,720 it allows us that at the same time our keyboard listener will run and listen for the input keystrokes. 49 00:04:14,060 --> 00:04:20,000 So all we have to do right now is actually delete the print key since we do not need it here anymore 50 00:04:20,000 --> 00:04:25,460 we created a function that will actually print the keys and let us save this. 51 00:04:25,460 --> 00:04:27,720 Now let's see how this actually works. 52 00:04:28,070 --> 00:04:38,020 If we run the key logger to dot you wipe we can get the invalid syntax so let us see what actually invalidates 53 00:04:38,030 --> 00:04:41,080 right here where we actually specify something wrong. 54 00:04:42,870 --> 00:04:44,590 Print keys global keys 55 00:04:49,420 --> 00:04:52,040 let's see what actually is wrong here. 56 00:04:52,050 --> 00:04:53,790 Can't really seem to see it. 57 00:04:58,910 --> 00:05:00,200 Print log. 58 00:05:00,200 --> 00:05:04,540 So we use the global keys function the global keys variable okay. 59 00:05:04,640 --> 00:05:13,940 We print the keys then we set them to be nothing and then we call our function. 60 00:05:13,940 --> 00:05:17,720 Import threading so this all should be good. 61 00:05:17,720 --> 00:05:21,030 Let me just check it out. 62 00:05:25,020 --> 00:05:29,140 It says invalid syntax in this function right here. 63 00:05:29,370 --> 00:05:32,370 So something right here is not coded properly. 64 00:05:32,390 --> 00:05:33,980 This global case is good 65 00:05:37,920 --> 00:05:44,490 maybe the invalid syntax is because we actually use the name print for our function which is already 66 00:05:44,490 --> 00:05:50,500 something that is in Python so let's change this to Freeport. 67 00:05:50,530 --> 00:05:53,560 We also use the report right here. 68 00:05:53,560 --> 00:06:01,410 We also need to call the report here or actually write here we actually want to use the print. 69 00:06:02,170 --> 00:06:09,370 Yeah that was actually the problem since here in this statement right here the the code didn't know 70 00:06:09,400 --> 00:06:14,950 if we actually call the function or use the print inbuilt you know that to print all the keys. 71 00:06:14,950 --> 00:06:20,560 That's why we got the incorrect syntax so make sure to rename your function to anything else you want 72 00:06:20,590 --> 00:06:24,870 except product the print option set for the print syntax. 73 00:06:24,910 --> 00:06:29,520 Make sure to rename it here as well and also make sure to rename it here as well. 74 00:06:29,530 --> 00:06:36,910 So let us go down here the letters and type your report then controller to save this and let us see 75 00:06:36,940 --> 00:06:41,560 how this will run right now as we can see we don't see anything if I just type you. 76 00:06:41,590 --> 00:06:47,960 Hello world we can see right after five seconds which changed from ten to five. 77 00:06:48,040 --> 00:06:54,250 We actually get printed out hello world and now in the next five seconds we will not get printed out 78 00:06:54,310 --> 00:06:59,430 the a world since we said the keys variable to be nothing right after we print it right. 79 00:06:59,680 --> 00:07:05,320 Just type your what is up question mark in the five seconds we will get what is up. 80 00:07:05,320 --> 00:07:07,530 Key shift and then the question mark. 81 00:07:07,570 --> 00:07:10,710 So our code works well let us know it. 82 00:07:10,750 --> 00:07:13,330 And let us add a few more things to it. 83 00:07:14,200 --> 00:07:20,860 So what we manage to do is actually print every five seconds our our keystrokes. 84 00:07:20,890 --> 00:07:26,500 And right now what we want to do is actually implement some of the keys that we also need to use right 85 00:07:26,500 --> 00:07:38,660 here so this statement right here will become the L Steve statement so l If l if for example or let's 86 00:07:38,660 --> 00:07:45,140 leave this to be l so for any other key and we will code the L if right here so right after this L if 87 00:07:46,320 --> 00:07:50,780 key so are key equals equals two key. 88 00:07:50,840 --> 00:07:52,800 Enter for example. 89 00:07:52,880 --> 00:07:58,750 Since entering something that people press a lot we want to add nothing to the fire to the two the keys 90 00:07:58,760 --> 00:08:01,780 actually so what we want to actually do is type here. 91 00:08:01,790 --> 00:08:05,200 Keys equals keys. 92 00:08:05,350 --> 00:08:06,340 Plus nothing. 93 00:08:06,410 --> 00:08:12,440 So same thing that we did in the previous video I believe we specify something like that right now. 94 00:08:12,440 --> 00:08:15,640 Keys equal keys plus nothing. 95 00:08:15,770 --> 00:08:22,020 We don't specify any space right here we just leave it like this then we run the another L statement 96 00:08:22,020 --> 00:08:27,940 for for example key equals key dot right. 97 00:08:27,960 --> 00:08:30,780 Which is for the right arrow on our keyboard. 98 00:08:31,080 --> 00:08:36,940 So what we want to do right now we want to add key keys. 99 00:08:36,950 --> 00:08:40,290 That's the name of our variable so don't confuse this. 100 00:08:40,370 --> 00:08:45,650 I should have named it something else since Keys and Key could be confusing but it doesn't really matter 101 00:08:45,650 --> 00:08:46,590 right now. 102 00:08:46,610 --> 00:08:51,800 Make sure to recognize that this key is something that we get from our function and that keys is the 103 00:08:51,800 --> 00:08:53,900 variable that we actually created. 104 00:08:53,900 --> 00:08:57,700 So keys equals. 105 00:08:57,770 --> 00:09:00,670 Same as before so keys plus nothing. 106 00:09:00,680 --> 00:09:11,070 We want to do that for all of the arrows so else if he equals equals keep the left keys equal keys nothing 107 00:09:11,910 --> 00:09:12,270 else. 108 00:09:12,300 --> 00:09:25,390 If key equals equals key dug up keys equal keys plus nothing at all we have to do is for the down arrow 109 00:09:25,390 --> 00:09:31,010 so key equals equals keyed up down keys equal. 110 00:09:31,280 --> 00:09:33,430 He's lost nothing. 111 00:09:33,430 --> 00:09:39,820 So what is specified right here is if someone presses the arrows this pace the enter basically it will 112 00:09:39,820 --> 00:09:48,530 not print those characters so now all we have to do right now is actually test for this. 113 00:09:48,560 --> 00:09:53,620 If it works so let us front the program and let us use some of the arrows right here. 114 00:09:54,590 --> 00:09:56,830 Let's use helo. 115 00:09:57,170 --> 00:09:59,910 You can see that we only get printed out helo. 116 00:09:59,990 --> 00:10:03,870 We don't can we don't get printed now tentatively don't get printed out. 117 00:10:03,910 --> 00:10:08,260 Upper the lower left and right arrow so we only get printed out the string. 118 00:10:08,280 --> 00:10:09,790 We type so let us use. 119 00:10:09,790 --> 00:10:15,980 Hello world we can see we get printed out it with me mistyped right here but doesn't matter if we could 120 00:10:15,980 --> 00:10:16,540 print it out. 121 00:10:16,530 --> 00:10:17,710 Hello world. 122 00:10:17,900 --> 00:10:19,890 Now let's see now that we created this. 123 00:10:19,940 --> 00:10:25,880 Let's see in the next video how we can actually write this to a file and implement it finally in our 124 00:10:25,880 --> 00:10:27,330 back door. 125 00:10:27,420 --> 00:10:31,850 So I hope you enjoyed this video and I hope I see you in the next one by.