Author Topic: How do computers receive input?  (Read 1042 times)

0 Members and 1 Guest are viewing this topic.

Offline kieron013

  • Thread Starter
  • Posts: 1
How do computers receive input?
« on: Wed, 14 June 2023, 06:10:12 »
Apologies if this is confusing, I'm not the best at explaining my thoughts. When I type in a letter or press enter or any other button, how does that turn into data? What does the computer do to turn a press of the "A" key into putting the letter A on my screen? Speed Test https://vidmate.bid/
« Last Edit: Thu, 15 June 2023, 11:15:40 by kieron013 »

Offline Findecanor

  • Posts: 4989
  • Location: Koriko
Re: How do computers receive input?
« Reply #1 on: Wed, 14 June 2023, 06:39:04 »
There are quite many steps involved.. This below is very simplified and generalised:

Over USB, the computer asks the keyboard regularly if there is any new data and if there is a new key event (press or release) then the keyboard will respond with a data packet. The data packet contains all keys that are pressed. Each key has a "usage code" number in the USB HID ("Human Interface Device") protocol's tables, and refers to the physical key, not a character code.

The operating system compares each new packet with the old, to see if there is any change. If there is, it will create a message with information about the new keyboard event.
Most operating system will route that message to the active window, and thus to the program that owns that window, and then the program will pass that message to the widget in the window that has keyboard focus. In many cases though, the event could be caught on the way and routed somewhere else: for instance if the key event involves media keys or a Windows key (on MS-Windows).
What the program does with the event is up to the program.

The message contains a number of which raw key is pressed (or released) and which character code it represents.
Each operating system will typically have its own table of key codes (that are different from the USB protocol's).
The character code is looked up by key code in the user's active key map. There are different key maps for different languages and regions, and also for special layouts such as "Dvorak".

The important thing to remember from a keyboarding perspective is that there are two logical keyboard layouts: First how the keyboard maps physical switches to codes that represent physical keys, and next how the operating system uses a "key map" to translate keys (and combinations of keys pressed together) into characters. (in ASCII or Unicode).
« Last Edit: Wed, 14 June 2023, 06:51:37 by Findecanor »
Man must shape his tools lest they shape him
-- Arthur Miller