A musical keyboard is the set of adjacent depressible levers or keys on a musical instrument. Keyboards typically contain keys for playing the twelve notes of the Western musical scale, with a combination of larger, longer keys and smaller, shorter keys that repeats at the interval of an octave. Depressing a key on the keyboard makes the instrument produce sounds--either by mechanically striking a string or tine (acoustic and electric piano, clavichord), plucking a string (harpsichord), causing air to flow through a pipe organ, striking a bell (carillon), or, on electric and electronic keyboards, completing a circuit (Hammond organ, digital piano, synthesizer). Since the most commonly encountered keyboard instrument is the piano, the keyboard layout is often referred to as the piano keyboard.
The twelve notes of the Western musical scale are laid out with the lowest note on the left; The longer keys (for the seven "natural" notes of the C major scale: C, D, E, F, G, A, B) jut forward. Because these keys were traditionally covered in ivory they are often called the white notes or white keys. The keys for the remaining five notes--which are not part of the C major scale—(i.e., C♯/D♭, D♯/E♭, F♯/G♭, G♯/A♭, A♯/B♭) (see Sharp and Flat) are raised and shorter. Because these keys receive less wear, they are often made of black colored wood and called the black notes or black keys. The pattern repeats at the interval of an octave.
The arrangement of longer keys for C major with intervening, shorter keys for the intermediate semitones dates to the 15th century. Many keyboard instruments dating from before the nineteenth century, such as harpsichords and pipe organs, have a keyboard with the colours of the keys reversed: the white notes are made of ebony and the black notes are covered with softer white bone. A few electric and electronic instruments from the 1960s and subsequent decades have also done this; Vox's electronic organs of the 1960s, Farfisa's FAST portable organs, Hohner's Clavinet L, one version of Korg's Poly-800 synthesizer and Roland's digital harpsichords.
Some 1960s electronic organs used reverse colors or gray sharps or naturals to indicate the lower part (or parts) of a single keyboard divided into two parts, each controlling a different registration or sound. Such keyboards accommodate melody and contrasting accompaniment without the expense of a second manual, and were a regular feature in Spanish and some English organs of the renaissance and baroque eras. The break was between middle C and C-sharp, or outside of Iberia between B and C. Broken keyboards reappeared in 1842 with the harmonium, the split occurring at E4/F4.
The chromatic range (also called compass) of keyboard instruments has tended to increase. Harpsichords often extended over five octaves (61+ keys) in the 18th century, while most pianos manufactured since about 1870 have 88 keys. Some modern pianos have even more notes (a Bösendorfer 290 "Imperial" has 97 keys and a Stuart & Sons model has 108 keys). While modern synthesizer keyboards commonly have either 61, 76 or 88 keys, small MIDI controllers are available with 25 notes. (Digital systems allow shifting octaves, pitch, and "splitting" ranges dynamically, reducing the need for dedicated keys.) Organs normally have 61 keys per manual, though some spinet models have 44 or 49. An organ pedalboard is a keyboard with long pedals played by the organist's feet. Pedalboards vary in size from 12 to 32 notes.
In a typical keyboard layout, black note keys have uniform width, and white note keys have uniform width and uniform spacing at the front of the keyboard. In the larger gaps between the black keys, the width of the natural notes C, D and E differ slightly from the width of keys F, G, A and B. This allows close to uniform spacing of 12 keys per octave while maintaining uniformity of seven "natural" keys per octave.
Over the last three hundred years, the octave span distance found on historical keyboard instruments (organs, virginals, clavichords, harpsichords, and pianos) has ranged from as little as 125 mm to as much as 170 mm. Modern piano keyboards ordinarily have an octave span of 164-165 mm; resulting in the width of black keys averaging 13.7 mm and white keys about 23.5 mm wide at the base, disregarding space between keys. Several reduced-size standards have been proposed and marketed. A 15/16 size (152 mm octave span) and the 7/8 DS Standard (140 mm octave span) keyboard developed by Christopher Donison in the 1970s and developed and marketed by Steinbuhler & Company. U.S. pianist Hannah Reimann has promoted piano keyboards with narrower octave spans and has a U.S. patent on the apparatus and methods for modifying existing pianos to provide interchangeable keyboards of different sizes.
There have been variations in the design of the keyboard to address technical and musical issues. The earliest designs of keyboards were based heavily on the notes used in Gregorian chant (the seven diatonic notes plus B-flat) and as such would often include B♭ and B♮ both as diatonic "white notes," with the B♮ at the leftmost side of the keyboard and the B♭ at the rightmost. Thus, an octave would have eight "white keys" and only four "black keys." The emphasis on these eight notes would continue for a few centuries after the "seven and five" system was adopted, in the form of the short octave: the eight aforementioned notes were arranged at the leftmost side of the keyboard, compressed in the keys between E and C (at the time, accidentals that low were very uncommon and thus not needed). During the sixteenth century, when instruments were often tuned in meantone temperament, some harpsichords were constructed with the G♯ and E♭ keys split into two. One portion of the G♯ key operated a string tuned to G♯ and the other operated a string tuned to A♭, similarly one portion of the E♭ key operated a string tuned to E♭, the other portion operating a string tuned to D♯. This type of keyboard layout, known as the enharmonic keyboard, extended the flexibility of the harpsichord, enabling composers to write keyboard music calling for harmonies containing the so-called wolf fifth (G-sharp to E-flat), but without producing aural discomfort in the listeners (see: Split sharp). The "broken octave," a variation of the aforementioned short octave, similarly used split keys to add accidentals left out of the short octave. Other examples of variations in keyboard design include the Jankó keyboard and the chromatic keyboard systems on the chromatic button accordion and bandoneón.
Simpler electronic keyboards have switches under each key. Depressing a key connects a circuit, which triggers tone generation. Most keyboards use a keyboard matrix circuit, in which eight rows and eight columns of wires cross -- thus, 16 wires can provide (8x8=) 64 crossings, which the keyboard controller scans to determine which key was pressed. The problem with this system is that it provides only a crude binary on/off signal for each key. Better electronic keyboards employ two sets of switches for each key that are slightly offset. By determining the timing between the activation of the first and second switches, the velocity of a key press can be determined -- greatly improving the performance dynamic of a keyboard. The best electronic keyboards have dedicated circuits for each key, providing polyphonic aftertouch.
Advanced electronic keyboards may provide hundreds of key touch levels  and have 88 keys, as most pianos do.
Despite their apparent similarity, keyboard instruments of different types require different techniques. The piano hammer mechanism produces a louder note the faster the key is pressed while the harpsichord's plectrum mechanism does not perceptibly vary the volume of the note with different touch on the keyboard. The pipe organ's volume and timbre are controlled by the flow of air from the bellows and the stops preselected by the player. Players of these instruments therefore use different techniques to color the sound. An arranger keyboard may be preset to produce any of a range of voices as well as percussion and other accompaniments that respond to chords played by the left hand.
Even though the keyboard layout is simple and all notes are easily accessible, playing requires skill. A proficient player has undertaken much training to play accurately and in tempo. Beginners seldom produce a passable rendition of even a simple piece due to lack of technique. The sequences of movements of the player's hands can be very complicated. Problems include wide-spanned chords, which can be difficult for people with small hands, chords requiring unusual hand positions that can initially be uncomfortable, and fast scales, trills and arpeggios.
Playing instruments with velocity sensitive (or dynamic) keyboards (i.e., that respond to varying playing velocity) may require finger independence, so that some fingers play "harder" while others play more softly. Pianists call this control of touch velocity voicing (not to be confused by a piano technician's "voicing" of a piano by modifying the hardness of the hammers). Keyboardists speak of playing harder and softer, or with more or less force. This may accurately describe the player's experience—but in the mechanics of the keyboard, velocity controls musical dynamics. The faster the player depresses the key, the louder the note. Players must learn to coordinate two hands and use them independently. Most music is written for two hands; typically the right hand plays the melody in the treble range, while the left plays an accompaniment of bass notes and chords in the bass range. Examples of music written for the left hand alone include several of Leopold Godowsky's 53 Studies on Chopin's Etudes, Maurice Ravel's Piano Concerto for the Left Hand and Sergei Prokofiev's Piano Concerto No. 4 for the left hand. In music that uses counterpoint technique, both hands play different melodies at the same time.
A number of percussion instruments share the keyboard layout, although they are not keyboard instruments with levers that are depressed to sound the notes. Instead, the performer of instruments such as the xylophone, marimba, vibraphone, and glockenspiel strikes the separate-sounding tone bar of metal or wood for each note using a mallet. These bars are laid out in the same configuration as a common keyboard.
There are some rare variations of keyboards with more or fewer than 12 keys per octave, mostly used in microtonal music, after the discoveries and theoretical developments of musician and inventor Julián Carrillo (1875-1965).
Some free-reed instrument keyboards such as accordions and Indian harmoniums include microtones. Electronic music pioneer Pauline Oliveros plays one of these. Egyptian belly-dance musicians like Hassam Ramzy use custom-tuned accordions so they can play traditional scales. The small Garmon accordion played in the Music of Azerbaijan sometimes has keys that can play microtones when a "shift" key is pressed.