Input
Input is anything that enters a computer from outside a running program — keystrokes, mouse movements, touches, microphone sound, camera images, sensor readings, files being opened, or packets arriving from a network — and the act of receiving it. It is the first of the four basic operations of a computer, the one that connects a machine to people and to the physical world, and it is the point where the outside world's untidiness meets a system that expects exactly defined values.
Every input device is a translator from some physical event into digital data. A keyboard turns the closing of a switch into a scan code, a mouse or trackpad reports movement as small numeric offsets, a touchscreen converts capacitance changes into coordinates, a microphone samples air pressure thousands of times per second, and a camera sensor converts light on each pixel into a number. Analog quantities such as sound and temperature pass through an analog-to-digital converter, which measures them at regular intervals and rounds each measurement to the nearest available level. Because this measuring always rounds and samples, digitized input is an approximation of reality, and its quality is bounded by how often and how finely it was measured.
Input reaches a program through the operating system, not directly from the hardware. When a key is pressed, the device controller signals the processor with an interrupt, the operating system's driver reads the scan code, translates it into a character according to the keyboard layout, and places an event in a queue. The application then receives that event, either by waiting for it or by checking a queue repeatedly. The alternative to interrupts, polling, wastes processor time asking devices whether anything has happened. Modern interfaces such as USB's Human Interface Device standard let one driver handle keyboards and mice from every manufacturer.
Input is not limited to people at devices; programs receive it constantly from other programs and machines. In Unix, a program reads from standard input, called stdin, which by default is the keyboard but can be redirected from a file or connected to another program's output through a pipe, an idea Ken Thompson added to Unix in 1973 at Douglas McIlroy's urging. Command-line arguments, environment variables, files, database queries, and network requests are all inputs too, and a web server's input is a stream of HTTP requests from strangers. Machine-learning systems add their own forms: a prompt to a language model, an image to a classifier, or a batch of sensor frames from a vehicle are all inputs the model treats as numbers.
Input has to be treated as untrusted, because the sender may be careless or hostile. The classic failures arise when a program assumes input is well-formed. A buffer overflow occurs when more data is written than space was reserved; the Morris worm of 1988 spread in part through such a flaw in the Unix finger service. SQL injection occurs when user-supplied text is pasted into a database command and interpreted as part of it. The defenses are validation, which checks that input has the expected type, range, and format, and safe handling, such as parameterized queries that keep data separate from commands. A related pitfall is assuming that input arrives in the form the user sees: text encoding, locale, and trailing whitespace regularly differ from what was intended.
A frequent misconception is that input and storage are the same thing. Input is the arrival of data into a running program; it exists only in memory until the program saves it somewhere. A typed sentence that is never saved vanishes when the program closes. Another is that input always means human action: sensors, scheduled jobs, and network messages feed far more of the world's data than keyboards do. Latency matters as well, since a game or a drawing tablet must deliver input within a few milliseconds to feel responsive, while a batch job can read its input hours before it is needed.
Read input as the doorway through which outside reality becomes data — translated by a device, delivered by the operating system, and only as safe to use as the checks the program performs before trusting it.