What an input device does
An input device converts a physical action into an electrical signal and then into digital data. The computer cannot sense a finger or a hand directly. It only receives patterns of bits.
Other input devices include touchscreens, microphones, scanners and cameras. The keyboard supplies discrete symbols, while the mouse supplies position and button information.
How a keyboard reports key presses
Under the keys, a keyboard has a grid of switches. A small controller in the keyboard scans the grid, finds which switch has closed or opened, and sends a scan code that identifies the key. It does not send the letter itself.
The operating system receives the scan code through a driver, which is software that talks to the hardware. It maps the code to a character using the active keyboard layout, such as QWERTY. This is why the same physical key can produce different letters on different layouts.
How a mouse reports movement
Most modern mice use an optical sensor. The sensor takes many small images of the surface per second and compares them to measure how far the mouse moved. It reports movement as relative changes in x and y, not as a fixed screen position.
The operating system adds these changes to the current pointer position. Button clicks and scroll wheel steps are sent as separate events. Resolution is often given in dots per inch (DPI), meaning counts reported per inch of movement.
A worked example of pointer movement
Suppose a mouse is set to 800 DPI and the pointer starts at x = 100 pixels. The user moves the mouse 0.5 inch to the right. The mouse reports 800 x 0.5 = 400 counts.
If the system maps one count to one pixel, with no acceleration, the pointer ends at 100 + 400 = 500 pixels. Many systems apply pointer acceleration or a speed setting, so the real distance on screen often differs.
Common misconceptions and where they appear
One misconception is that a keyboard sends letters. It usually sends key codes, and software decides the character. Another is that a mouse knows where the pointer is on screen. It reports only motion, and the operating system tracks position.
Programs receive input as events. A text editor reacts to key events, and a game reads mouse movement to turn a camera. Command line tools read keyboard input as a stream of characters from standard input.
Key terms
- Input device
- Hardware that sends data from a user or the environment into a computer.
- Scan code
- A number a keyboard sends to identify which key was pressed or released.
- Driver
- Software that lets the operating system communicate with a hardware device.
- Keyboard layout
- The mapping from key codes to characters, such as QWERTY.
- DPI
- Dots per inch, the number of movement counts a mouse reports per inch of travel.
- Event
- A message from the operating system telling a program that something happened, such as a key press or click.