The idea for a keyboard is far older then computers. Typewriters existed prior which inspired modern keyboards.
There are two main types of keyboards. Mechanical which use a spring or rubber to pop the key back up and while the key is down it makes a connection. Or keyboards that interupt the flow of electricity, effectivly the reverse.
As we have discusses keyboards in class and their relation to the ASCII table, I will not contrinue here, but remember that most keyboards are directally interfaced with your operating system so they are very efficient.