﻿1
00:00:00,590 --> 00:00:06,410
‫Hello and welcome to this lecture and this lecture, we're going to implement the Caps lock, this will

2
00:00:06,410 --> 00:00:11,460
‫allow us to easily use capital and lowercase letters in our shell.

3
00:00:12,110 --> 00:00:15,220
‫Currently, you will notice we can only use uppercase letters.

4
00:00:15,230 --> 00:00:18,840
‫There's no way to turn that to lowercase letters.

5
00:00:19,280 --> 00:00:25,350
‫So after implementing caps, Lock will be able to use both uppercase and lowercase letters.

6
00:00:25,760 --> 00:00:27,660
‫So let's let's begin.

7
00:00:28,460 --> 00:00:30,320
‫Head over to Keyboardists C.

8
00:00:31,710 --> 00:00:40,260
‫Which is in the keyboard directory and keyboard that s. so we're going to go void's keyboard set caps

9
00:00:40,260 --> 00:00:44,930
‫lock and we're going to say Buhle State.

10
00:00:45,960 --> 00:00:49,230
‫OK, so the state will be true or false.

11
00:00:49,260 --> 00:00:52,050
‫OK, so what we should say is keyboard set, caps lock.

12
00:00:54,780 --> 00:00:55,020
‫Yeah.

13
00:00:55,020 --> 00:00:56,000
‫I'll tell you what we'll do.

14
00:00:56,010 --> 00:00:57,560
‫Actually this should be an integer.

15
00:00:57,660 --> 00:01:00,910
‫OK, keyboard set caps lock and state.

16
00:01:00,930 --> 00:01:10,680
‫OK, now go to keyboard Hajj and we're just going to go to fine keyboard caps lock on and that'll be

17
00:01:10,680 --> 00:01:13,560
‫one to find keyboard caps lock

18
00:01:16,890 --> 00:01:18,390
‫off and that'll be zero.

19
00:01:18,420 --> 00:01:20,580
‫OK, so that's just a bit cleaner, right.

20
00:01:21,680 --> 00:01:23,580
‫We can even have its own type if you want.

21
00:01:23,880 --> 00:01:24,950
‫So yeah, we'll do that too.

22
00:01:24,960 --> 00:01:25,560
‫Let's go.

23
00:01:26,430 --> 00:01:27,540
‫Typedef in it.

24
00:01:28,810 --> 00:01:36,090
‫Keyboard caps lock state if you find they are having a lot of these different things.

25
00:01:36,090 --> 00:01:42,210
‫So caps lock on them lock on and all of this, then you might want to have Flagg's instead and just

26
00:01:42,210 --> 00:01:42,860
‫toggle them.

27
00:01:43,770 --> 00:01:48,300
‫But just to keep things simple for you all, we're not going to do that here, we're just going to have

28
00:01:48,300 --> 00:01:49,570
‫a caps lock state.

29
00:01:49,640 --> 00:01:56,070
‫OK, so keyboard set caps lock and they provide us keyboard caps, lock state, OK, which can either

30
00:01:56,070 --> 00:02:02,130
‫be on or off and you can make that an enumeration if you prefer.

31
00:02:02,730 --> 00:02:08,670
‫So we're now going to want to go to keyboard that Hajj and we're just going to say keyboard caps lock

32
00:02:08,670 --> 00:02:10,170
‫state key.

33
00:02:10,170 --> 00:02:11,520
‫Uh, caps lock step.

34
00:02:15,950 --> 00:02:16,890
‫Just like that.

35
00:02:16,910 --> 00:02:17,360
‫OK.

36
00:02:17,600 --> 00:02:22,510
‫And that'll stop the state of the keyboard, whether whether the caps locks on or off.

37
00:02:22,970 --> 00:02:28,970
‫No, obviously if you have multiple keyboards, then they won't sync with each other with the caps lock.

38
00:02:28,970 --> 00:02:35,510
‫OK, so you may decide to want to put this in the global scope so that the caps lock state affects every

39
00:02:35,510 --> 00:02:35,950
‫keyboard.

40
00:02:35,960 --> 00:02:38,540
‫But personally, I don't think we need to really.

41
00:02:40,040 --> 00:02:46,430
‫So Justin Keyboard's set, caps lock, we're going to do, uh, struct keyboard keyboard, so they're

42
00:02:46,430 --> 00:02:48,400
‫also going to have to provide us a keyboard, OK?

43
00:02:48,890 --> 00:02:53,980
‫And then we're just going to say keyboard caps, lock state equals state just like that.

44
00:02:53,990 --> 00:03:00,140
‫OK, and now we're going to say in it, keyboard get caps lock

45
00:03:03,290 --> 00:03:10,040
‫and we're going to put the struct keyboard in here and that's just going to return the keyboard caps

46
00:03:10,040 --> 00:03:11,900
‫lock state just like that, guys.

47
00:03:11,930 --> 00:03:15,470
‫OK, so yeah that looks OK.

48
00:03:16,010 --> 00:03:19,700
‫Let's put these functions in the header files so we can access them outside.

49
00:03:26,900 --> 00:03:31,130
‫And we also want to return Keibel caps lock state, not an inch.

50
00:03:31,560 --> 00:03:38,420
‫So that was my mistake just for the keep or get caps lock, OK, and change the one here as well.

51
00:03:38,750 --> 00:03:39,590
‫Just like that.

52
00:03:40,490 --> 00:03:44,750
‫And I'll head over to Classic Dot, see, and we're ready to begin using those functions.

53
00:03:45,500 --> 00:03:53,780
‫OK, so the first thing we're going to do is during initialization, we're just going to go classic

54
00:03:53,780 --> 00:04:05,990
‫keyboard and we're going to go keyboard set caps lock and we're going to go ampersand, classic keyboarder

55
00:04:06,230 --> 00:04:13,520
‫and we're going to say keyboard caps lock off and we're just doing this just to test the functionality.

56
00:04:13,530 --> 00:04:16,580
‫So obviously we want to toggle the caps lock yet.

57
00:04:16,610 --> 00:04:22,310
‫OK, but we're just going to turn the caps lock off here to check to check if we're able to put things

58
00:04:22,310 --> 00:04:23,470
‫in lowercase, OK?

59
00:04:23,480 --> 00:04:27,980
‫And then once we know we can do that, then we can make it so we can toggle the caps, lock on or off,

60
00:04:28,640 --> 00:04:28,980
‫OK.

61
00:04:29,000 --> 00:04:35,420
‫So now just by here, after we get the char code from the keyboard scans, that one, we're going to

62
00:04:35,420 --> 00:04:46,340
‫say if the caps lock is not down, so we go keyboard, get caps lock and we're going to pass in the

63
00:04:46,340 --> 00:04:50,120
‫classic keyboard the address of the class, the keyboard, I should say.

64
00:04:50,120 --> 00:04:54,690
‫OK, and we're going to make sure that we check the status down.

65
00:04:54,710 --> 00:04:59,930
‫OK, so we're going to go equals equals keyboard caps lock off.

66
00:05:00,170 --> 00:05:09,400
‫And if that's the case, then we need to take the character here and make it lowercase.

67
00:05:09,410 --> 00:05:14,600
‫So firstly, we need to check that it's actually from A to Z, because if it's not from A to Z, we

68
00:05:14,600 --> 00:05:15,600
‫shouldn't even change it.

69
00:05:15,620 --> 00:05:19,640
‫OK, so let's stop again the ASCII table up and you'll understand.

70
00:05:19,640 --> 00:05:23,990
‫I'm sure all of you have heard of the ASCII table and I'm sure you all understand it very well.

71
00:05:24,860 --> 00:05:26,540
‫But just in case, will go over it.

72
00:05:27,260 --> 00:05:36,440
‫So we can see here that capital A's decimal sixty five and the lowercase A is ninety seven.

73
00:05:36,810 --> 00:05:44,090
‫OK, we can convert a capital A for example to a lowercase A by doing a simple equation.

74
00:05:44,100 --> 00:05:46,670
‫So if we want to get a python here.

75
00:05:50,100 --> 00:05:55,120
‫And we did ninety seven minus sixty five.

76
00:05:55,800 --> 00:06:04,500
‫We get 32, so all we do is, is we add 32 to any uppercase character and it becomes a lowercase character.

77
00:06:04,890 --> 00:06:07,560
‫OK, let's take decimal 68.

78
00:06:07,560 --> 00:06:14,040
‫Ferdy Ferdy, as an example, we're going to go sixty eight plus thirty two and we get one hundred.

79
00:06:14,040 --> 00:06:19,590
‫And if you look at one hundred decimal hundred that is lowercase D so you can see the ASCII tables arranged

80
00:06:19,590 --> 00:06:21,030
‫like this in such a way.

81
00:06:21,030 --> 00:06:27,420
‫So you can do math like this on it and be able to easily convert to lowercase, OK or uppercase.

82
00:06:28,260 --> 00:06:30,450
‫Now we do need to check that it's in bounds.

83
00:06:30,450 --> 00:06:37,350
‫So we need to check if the character is between Capital A. and Capital Z and if that's true, then we

84
00:06:37,350 --> 00:06:41,910
‫can perform that that that mathematical operations.

85
00:06:41,920 --> 00:06:51,780
‫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

86
00:06:51,780 --> 00:07:00,540
‫above or equal capital and C is below equal capital Z.

87
00:07:01,460 --> 00:07:05,360
‫In which case it's a character that should be converted to lowercase.

88
00:07:05,610 --> 00:07:14,160
‫So we just go C minus equals 32, which is the difference between now plus equals not minus plus equals

89
00:07:14,160 --> 00:07:18,750
‫32, which is the difference in the ASCII table, as I just showed you with Python just then.

90
00:07:19,410 --> 00:07:19,930
‫Uh.

91
00:07:20,430 --> 00:07:23,280
‫So why do we check if the caps lock is off and not on?

92
00:07:24,000 --> 00:07:28,640
‫Because our entire scan scans, that one is in uppercase.

93
00:07:28,830 --> 00:07:32,040
‫That's why if it was in lower case, then we'd do the opposite.

94
00:07:32,040 --> 00:07:39,180
‫We would check if the if the caps lock was on and we check between A and between lowercase, A. and

95
00:07:39,180 --> 00:07:39,720
‫lowercase.

96
00:07:40,890 --> 00:07:47,700
‫But because we're checking the caps lock itself and we check between capital and Z because of the way

97
00:07:47,700 --> 00:07:48,840
‫the scan said one is.

98
00:07:49,080 --> 00:07:49,950
‫So that should work.

99
00:07:49,950 --> 00:07:50,700
‫OK guys.

100
00:07:50,880 --> 00:07:52,500
‫So we're nearly ready to build this.

101
00:07:52,500 --> 00:07:59,580
‫But before we do, just go to keyboard dot Hajj because we missed the semicolon there on keyboard get

102
00:07:59,580 --> 00:08:00,280
‫caps lock.

103
00:08:00,300 --> 00:08:01,920
‫OK, yeah.

104
00:08:01,940 --> 00:08:04,050
‫So once you've done that, we can go ahead and build this.

105
00:08:04,050 --> 00:08:06,870
‫Just go make clean build that S.H..

106
00:08:09,860 --> 00:08:15,860
‫And we can see that works absolutely fine if you run that, we should see lower case when we type,

107
00:08:16,010 --> 00:08:16,730
‫which we do.

108
00:08:17,480 --> 00:08:18,560
‫Hello, how are you?

109
00:08:19,580 --> 00:08:20,220
‫Excellent.

110
00:08:20,690 --> 00:08:22,860
‫So, yeah, congratulations on that.

111
00:08:22,880 --> 00:08:26,680
‫Guys, we now have the lower case implemented.

112
00:08:27,020 --> 00:08:30,920
‫We now need to just make the toggling of the caps lock and we are finished.

113
00:08:31,490 --> 00:08:38,570
‫So just scroll to the top of this file and we're just going to go to find define classic keyboard's

114
00:08:38,570 --> 00:08:39,050
‫caps.

115
00:08:39,050 --> 00:08:45,710
‫Lock equals zero x three a system don't the equals sign just type six three A..

116
00:08:46,250 --> 00:08:48,450
‫Now that's the code for the caps lock.

117
00:08:48,480 --> 00:08:55,070
‫OK, so scroll down here and just by here, just above line 75.

118
00:08:56,240 --> 00:09:00,930
‫No, no, no, below the line 78, where we check the key was released.

119
00:09:01,370 --> 00:09:09,950
‫We're just going to say if scanned code is equal to a classic keyboard caps lock.

120
00:09:12,260 --> 00:09:18,710
‫So when I was just going to go keyboard set, caps lock, classic keyboard.

121
00:09:20,390 --> 00:09:29,810
‫I like Shippen ampersand there, guys, and we're going to say keyboard caps, lock state, all state

122
00:09:30,590 --> 00:09:36,260
‫equals keyboard get caps, lock ampersand, classic keyboard.

123
00:09:36,260 --> 00:09:40,840
‫And you could make a toggle function if you wanted, but we'll just do it like this for now.

124
00:09:41,360 --> 00:09:52,700
‫And we're going to say if the old state is equal to caps, lock on then use keyboard caps lock off.

125
00:09:54,320 --> 00:09:57,740
‫Otherwise use keyboard caps lock on.

126
00:09:57,770 --> 00:09:59,010
‫So a bit of a tannery here.

127
00:09:59,030 --> 00:10:04,720
‫OK, so hold steady because zikos caps lock on, then use caps lock off.

128
00:10:04,730 --> 00:10:06,020
‫Otherwise caps lock on.

129
00:10:06,020 --> 00:10:06,650
‫Perfect.

130
00:10:07,370 --> 00:10:08,630
‫So that should work.

131
00:10:08,630 --> 00:10:12,620
‫OK, so if we just go make clean bill to Hajj.

132
00:10:17,100 --> 00:10:25,300
‫Kevin Hyram, you just type something, no press caps, lock and type again, press caps, lock type

133
00:10:25,300 --> 00:10:27,310
‫again, press caps lock type again.

134
00:10:27,670 --> 00:10:29,050
‫So you can see that works now.

135
00:10:29,060 --> 00:10:31,630
‫We now have the ability to use the caps lock.

136
00:10:32,120 --> 00:10:38,120
‫Now you'll notice if you start the pro, if you start the operating system with your caps lock on it.

137
00:10:38,170 --> 00:10:44,590
‫It'll still think caps lock is off the mask because we don't care about the actual state of the caps.

138
00:10:44,590 --> 00:10:47,200
‫Lock one, the OS boots.

139
00:10:47,470 --> 00:10:49,080
‫We just assume that it's off.

140
00:10:49,480 --> 00:10:54,250
‫OK, if you want to take this a step further, you can use the keyboard commands to determine if the

141
00:10:54,250 --> 00:10:56,410
‫caps lock is on or off state.

142
00:10:57,080 --> 00:11:03,700
‫However, we don't need to get on that because this is a perfectly acceptable implementation.

