‫Hello and welcome to this lecture and this lecture, we're going to implement the Caps lock, this will
‫allow us to easily use capital and lowercase letters in our shell.
‫Currently, you will notice we can only use uppercase letters.
‫There's no way to turn that to lowercase letters.
‫So after implementing caps, Lock will be able to use both uppercase and lowercase letters.
‫So let's let's begin.
‫Head over to Keyboardists C.
‫Which is in the keyboard directory and keyboard that s. so we're going to go void's keyboard set caps
‫lock and we're going to say Buhle State.
‫OK, so the state will be true or false.
‫OK, so what we should say is keyboard set, caps lock.
‫Yeah.
‫I'll tell you what we'll do.
‫Actually this should be an integer.
‫OK, keyboard set caps lock and state.
‫OK, now go to keyboard Hajj and we're just going to go to fine keyboard caps lock on and that'll be
‫one to find keyboard caps lock
‫off and that'll be zero.
‫OK, so that's just a bit cleaner, right.
‫We can even have its own type if you want.
‫So yeah, we'll do that too.
‫Let's go.
‫Typedef in it.
‫Keyboard caps lock state if you find they are having a lot of these different things.
‫So caps lock on them lock on and all of this, then you might want to have Flagg's instead and just
‫toggle them.
‫But just to keep things simple for you all, we're not going to do that here, we're just going to have
‫a caps lock state.
‫OK, so keyboard set caps lock and they provide us keyboard caps, lock state, OK, which can either
‫be on or off and you can make that an enumeration if you prefer.
‫So we're now going to want to go to keyboard that Hajj and we're just going to say keyboard caps lock
‫state key.
‫Uh, caps lock step.
‫Just like that.
‫OK.
‫And that'll stop the state of the keyboard, whether whether the caps locks on or off.
‫No, obviously if you have multiple keyboards, then they won't sync with each other with the caps lock.
‫OK, so you may decide to want to put this in the global scope so that the caps lock state affects every
‫keyboard.
‫But personally, I don't think we need to really.
‫So Justin Keyboard's set, caps lock, we're going to do, uh, struct keyboard keyboard, so they're
‫also going to have to provide us a keyboard, OK?
‫And then we're just going to say keyboard caps, lock state equals state just like that.
‫OK, and now we're going to say in it, keyboard get caps lock
‫and we're going to put the struct keyboard in here and that's just going to return the keyboard caps
‫lock state just like that, guys.
‫OK, so yeah that looks OK.
‫Let's put these functions in the header files so we can access them outside.
‫And we also want to return Keibel caps lock state, not an inch.
‫So that was my mistake just for the keep or get caps lock, OK, and change the one here as well.
‫Just like that.
‫And I'll head over to Classic Dot, see, and we're ready to begin using those functions.
‫OK, so the first thing we're going to do is during initialization, we're just going to go classic
‫keyboard and we're going to go keyboard set caps lock and we're going to go ampersand, classic keyboarder
‫and we're going to say keyboard caps lock off and we're just doing this just to test the functionality.
‫So obviously we want to toggle the caps lock yet.
‫OK, but we're just going to turn the caps lock off here to check to check if we're able to put things
‫in lowercase, OK?
‫And then once we know we can do that, then we can make it so we can toggle the caps, lock on or off,
‫OK.
‫So now just by here, after we get the char code from the keyboard scans, that one, we're going to
‫say if the caps lock is not down, so we go keyboard, get caps lock and we're going to pass in the
‫classic keyboard the address of the class, the keyboard, I should say.
‫OK, and we're going to make sure that we check the status down.
‫OK, so we're going to go equals equals keyboard caps lock off.
‫And if that's the case, then we need to take the character here and make it lowercase.
‫So firstly, we need to check that it's actually from A to Z, because if it's not from A to Z, we
‫shouldn't even change it.
‫OK, so let's stop again the ASCII table up and you'll understand.
‫I'm sure all of you have heard of the ASCII table and I'm sure you all understand it very well.
‫But just in case, will go over it.
‫So we can see here that capital A's decimal sixty five and the lowercase A is ninety seven.
‫OK, we can convert a capital A for example to a lowercase A by doing a simple equation.
‫So if we want to get a python here.
‫And we did ninety seven minus sixty five.
‫We get 32, so all we do is, is we add 32 to any uppercase character and it becomes a lowercase character.
‫OK, let's take decimal 68.
‫Ferdy Ferdy, as an example, we're going to go sixty eight plus thirty two and we get one hundred.
‫And if you look at one hundred decimal hundred that is lowercase D so you can see the ASCII tables arranged
‫like this in such a way.
‫So you can do math like this on it and be able to easily convert to lowercase, OK or uppercase.
‫Now we do need to check that it's in bounds.
‫So we need to check if the character is between Capital A. and Capital Z and if that's true, then we
‫can perform that that that mathematical operations.
‫So if we just go back to Visual Studio Code and we can work with that, so we're going to say if C is
‫above or equal capital and C is below equal capital Z.
‫In which case it's a character that should be converted to lowercase.
‫So we just go C minus equals 32, which is the difference between now plus equals not minus plus equals
‫32, which is the difference in the ASCII table, as I just showed you with Python just then.
‫Uh.
‫So why do we check if the caps lock is off and not on?
‫Because our entire scan scans, that one is in uppercase.
‫That's why if it was in lower case, then we'd do the opposite.
‫We would check if the if the caps lock was on and we check between A and between lowercase, A. and
‫lowercase.
‫But because we're checking the caps lock itself and we check between capital and Z because of the way
‫the scan said one is.
‫So that should work.
‫OK guys.
‫So we're nearly ready to build this.
‫But before we do, just go to keyboard dot Hajj because we missed the semicolon there on keyboard get
‫caps lock.
‫OK, yeah.
‫So once you've done that, we can go ahead and build this.
‫Just go make clean build that S.H..
‫And we can see that works absolutely fine if you run that, we should see lower case when we type,
‫which we do.
‫Hello, how are you?
‫Excellent.
‫So, yeah, congratulations on that.
‫Guys, we now have the lower case implemented.
‫We now need to just make the toggling of the caps lock and we are finished.
‫So just scroll to the top of this file and we're just going to go to find define classic keyboard's
‫caps.
‫Lock equals zero x three a system don't the equals sign just type six three A..
‫Now that's the code for the caps lock.
‫OK, so scroll down here and just by here, just above line 75.
‫No, no, no, below the line 78, where we check the key was released.
‫We're just going to say if scanned code is equal to a classic keyboard caps lock.
‫So when I was just going to go keyboard set, caps lock, classic keyboard.
‫I like Shippen ampersand there, guys, and we're going to say keyboard caps, lock state, all state
‫equals keyboard get caps, lock ampersand, classic keyboard.
‫And you could make a toggle function if you wanted, but we'll just do it like this for now.
‫And we're going to say if the old state is equal to caps, lock on then use keyboard caps lock off.
‫Otherwise use keyboard caps lock on.
‫So a bit of a tannery here.
‫OK, so hold steady because zikos caps lock on, then use caps lock off.
‫Otherwise caps lock on.
‫Perfect.
‫So that should work.
‫OK, so if we just go make clean bill to Hajj.
‫Kevin Hyram, you just type something, no press caps, lock and type again, press caps, lock type
‫again, press caps lock type again.
‫So you can see that works now.
‫We now have the ability to use the caps lock.
‫Now you'll notice if you start the pro, if you start the operating system with your caps lock on it.
‫It'll still think caps lock is off the mask because we don't care about the actual state of the caps.
‫Lock one, the OS boots.
‫We just assume that it's off.
‫OK, if you want to take this a step further, you can use the keyboard commands to determine if the
‫caps lock is on or off state.
‫However, we don't need to get on that because this is a perfectly acceptable implementation.