Yep. The mapping from keycodes to ASCII is done somewhere in the operating system. The word "scancode" is sometimes used interchangeably, and sometimes not.
There are different keyboard protocols over the cables.
The "AT" and "PS/2" protocols are the same, just different-sized connectors. It is a serial protocol (but not RS-232) where the keyboard sends different codes for a key when it is pressed and when it is released. Codes can also be one or multiple bytes long.
The USB keyboard protocol(s) is quite complex. First there is the USB protocol, then there is the "HID Keyboard" protocol on top of USB where the keyboard periodically sends a report telling which keys are pressed. The report contains an array of six keycodes and a 8-bit bitfield . Each USB keycode is one byte long. The keycode 0 means "no key". The bitfield tells which modifiers are pressed: Shift, Alt, Ctrl and "GUI" (Windows key) for the left and right side - that makes eight. (The Menu key is not a modifier)
The size of this array is why some keyboards are said to be limited to "6-key rollover" over USB. If a keyboard wants to report more pressed keys, then it will have to pull a trick: one way is to present itself to the PC as a USB hub with two or more keyboards attached. but that can be quite complicated.
There is also a special USB "keyboard boot protocol" used only during boot, which is needed for getting access to the BIOS, but many keyboards don't support that.
I have used the word "PC" here, but USB keyboards work the same way when connected to a Macintosh. Both the Windows key and the Command key are interpreted as "GUI" keys.
Another thing you should know is that the Caps Lock, Scroll Lock and Num Lock lamps are controlled by the PC -- not by the keyboard. The states of the lamps don't affect how the keyboard operates.