Hello everybody and welcome back to the second tutorial of our kg.
And in the previous tutorial we coded this little program right here which is key logger not a wonder
pie which actually adds the keystrokes to be file called key logger on the extreme.
But we noticed once we actually run the file so let's run it key logger won the pie and we just type
your hello world and we call the program if we catch the key logger that the file that we received from
it it actually prints out these weird letters right here with these apostrophes between each letter
and with these you will between each letter.
So what we want to do is actually get rid of that and how will we do that.
Well let us actually make another program that's called a key logger to the PI and let's actually make
first eat the import.
So import key pi and put the keyboard I believe should be something like this.
Let's start off with the same thing.
So same as the previous keyboard underscore listener key equals pi input not keyboard not listener.
And we want to use the on press function with the two hour process keys Ross's keys.
Then we use the same as before so with keyboard underscore listener.
We actually keyboard underscore listener and the join and right now since we set up our listener right
now we need to write a function that will actually get rid of the process.
I don't need to see right here.
So let me just delete one process on the score keys and we implement key in that function.
And right now what we want to actually do is we want to try and actually print the letters first.
Without those apostrophes.
So how we would do that.
We can actually do that with using the key itself and basically making the chart.
Now there is a simple thing in Python that we can use which is key the chart to do that.
So let us see how that look like.
So let us create a variable called for example keys and let's actually add nothing to it then use the
same variable which is global Keys where we will actually store the keys itself.
So let us try to just type your keys.
Equal keys lost the string of key dot char now before the previous video we basically did something
similar just we didn't have this dot Charlot right here and all we want to do right now I know that.
Check this out is actually print keys so let's see what this will do.
It will process the key to our function then since our keys is nothing it will add to our variable keys
it will add the string of the key dot char then it will print the keys.
Now this will print the keys forever as long as we are running this program and typing something in
the keyboard.
So let us control all this.
No control excel at this front the key logger just make it an executable key logger to the PI.
And if we run it whoops we just closed this.
If we run it once again and type your hello world you will see that it will stop the word hello first
and then we will get an error called attribute error.
Now the reason why we got this attribute error is because our program worked perfectly while we were
typing the letters but as soon as I went to actually type the spacebar it said key object has no attribute
char since the spacebar key actually doesn't have any character that actually represents it and that's
why we get this error.
So let me show you once again see all around key logger the PI and just up here Shell lo and then case
we once again get the same error.
So what we want to do right now is actually implement try and accept function that will actually use
this arrow as an accept.
So we want to cope with this error since this is the error to get for every left for every basically
key that we type in such a space bar delete backspace enter and so on.
All of those keys that actually do not have a character representation.
So we want to actually implement that in our key logger as well.
But what is good about our second key logger is that you saw that we do not have the weird apostrophe
between each letter anymore.
We just get the basic output of the string itself now we also need a little bit more work on this so
don't worry this is not the ending projects.
Let us before we do that Randi try so we will try to actually add this the character version of the
key to our variable keys.
And in case that doesn't work that means that the character or the key that we typed in doesn't really
have the character representation.
So we want to use except and then the error that we copied which is attribute error.
And then we have to press two dots.
And what we want to do is basically
run and if l statement right here.
So for example we know that in our previous video.
Let me just save this and leave it like this for now just to show you if I copy the key logger dot to
steal from our previous video you can see that once this press space it actually prints key dot space
so we can use this for example to process the key and add if key equals key dot space then we will add
something to the Keys variable.
So let us see what they actually mean by that.
So let us go back to our key logger to the PI and if I just type here
if key equals equals key dot space which is what prints out a one in our previous tutorial once we actually
type spacebar.
Well let's see what we can actually add to our keys variable.
So keys would be
Bob's everything previously so keys and then plus what the best thing for students Barry's is basically
just an empty space.
So make sure type double quotes and an empty space and then another double quotes.
So this will add an actual space bar between every
every time we actually print space so let us see how this will work.
Let us save this.
Now let's just run it once again.
So how low.
And if I just type your space and type your world you can see it prints out hello world right here.
We didn't get the error or no character for space.
It only printed the empty spot right here.
But we also need to do the same for every other character that doesn't have the implementation of or
basically the representation in character wise.
So right.
We want what we want to do right here is for now on just type here else for any other character that
doesn't have the string key char we want to type your keys.
Equal keys plus and then empty space so we can actually make distance between the regular characters
and for example and enter a backspace to delete a tab and shift or and so on and we want to add the
string of that key.
Now as I said before we are here using only the key and not key the char since if we actually specify
the key to char we would get the error once again you know you want to specify only the string of the
key for every every basically Batman or keyboard that doesn't have the character representation.
So and after that we also want to add an empty space so we can actually differentiate them.
Let's save this and see how this will actually work.
So if a control X two exits key logger to that pi if I just type here Hello World and the key tab shift
backspace you can see it prints all of these right here so what we want to do is actually add even for
these other things.
We want to add.
Basically the representation and characters for all of them.
Now for shift we can actually we can actually make the enter to be a new line.
We can make the key step to be an empty space as well backspace could delete but we can also make that
an empty space as well or we can just leave it like this so we know what the user has type so key enter
basically means the use of type enter tab means tab and so on.
Well let me just close this program right here and that will be about it for this tutorial.
We will continue actually making our key logger better in the next tutorial and then we will actually
implemented in our back door.
So hope you enjoyed this video and I hope I see you in the next one by.