How Software Deals with Key Presses - Computerphile

preview_player
Показать описание
Once you've pressed a key on the keyboard and the signal gets to the computer, what happens next? Dr Steve Bagley on the software side of a key-press.

This video was filmed and edited by Sean Riley.

Рекомендации по теме
Комментарии
Автор

At the hardware level on the keyboard, not all keys are treated equal. That's because most modifier keys are often held down while another key is pressed, and if you have too many at once, that could cause more of a path than a single intersection in the matrix. On gaming keyboards, there might be special care on further keys, such as WASD, in order to detect them better.

Tahgtahv
Автор

10:38 All keys are equal, but some keys are more equal than others.

KenHilton
Автор

4:05 Not just a security issue: think about languages that require a front-end processor (e.g. Chinese/Japanese/Korean) to translate keystrokes into a large character set: putting this in userland makes it more flexible, replaceable, configurable etc.

lawrencedoliveiro
Автор

Two things not addressed were: how key bounce is handled and how key release/repeat is handled. A long time ago, I wrote a GUI for DOS that looked a lot like the NetWare interface. The keyboard was relatively easy to handle. The complex part was handling keyboard/mouse interactions.

BlankBrain
Автор

The IBM model M gave special treatment to the modifier keys. It used a matrix where pressing 3 or more keys would sometimes not register all of them properly. Since the modifier keys are by design intended to be pressed with other keys, they were made immune to that issue with a dedicated line.

benoitrousseau
Автор

The handling of keys pressed by the window server is an iterresting point as this is where window focus stealing can have some side effects. Like typing in a password and whilst some application loads (like a texteditor of word) and it’s main window pops up in the front and your keystrokes get sent to word instead of the password dialogue box. This is a serious issue that still hasn’t been fixed in windows and would make a nice suggestion for a computerphile video.

dykodesigns
Автор

my keypresses go thru so much refinement, and yet my posts are still terrible

tibipics
Автор

Probably not gonna write a program like that, but you could.
Me:
Opens up the code editor
Name your project: Tom and Jerry keyboard tool.c

orlovsskibet
Автор

Here's how keys are handled on Linux:

Low level kernel
- Interrupt handler

Kernel modules/device drivers (for USB)
- uhci_hcd or ohci_hcd or ehci_hcd
- usbcore
- usbhid or usbmouse + usbkbd

Kernel modules/device drivers (for IBM PS/2 mini-DIN and AT connectors)
- atkbd

Kernel subsystem
- ioctls
- evdev

User-space
- libevdev (library for device events)

Window server
- xf86-input-evdev (direct input handler) or
- libinput -> xf86-input-libinput (libinput via X) or
- libinput -> Weston (libinput via Wayland)

For X:
- X window system
- X client (Xlib/XCB or toolkit like Qt)

For Wayland
- Weston
- Wayland client

Other software was involved like udev to detect which device to use and extensions like X keyboard extension (Xkb) to interpret key codes which is shared by X and Wayland.

Furiends
Автор

Don't keep this video on "hidden" please

Rolfdv
Автор

10:25
- are all keys treated equally?
- the short answer is: yes; the long answer is: no.
"yes" is longer than "no". contradictory statement detected
:)

dandan
Автор

Operating systems are these ingenious pieces of software that make sure you can type at least half a sentence before realizing that your key presses go to absolutely none of the windows on your screen at the moment.

AttilaAsztalos
Автор

Re “are all keys treated equally?”: In the USB HID protocol, modifier keys are handled in a special way: their state is sent as a bitmap (8 modifiers in one byte). For all other keys, the keyboard sends a list of the keys that are currently pressed.

edgarbonet
Автор

— The short answer is yes. While the long answer is no.
While, actually, «yes» is 50% longer than «no» is.

jkobain
Автор

I suspect a lot of the increased latency is down to font rendering and window redraws. Given that older systems had hardware text screens that you just had to put a character code into a memory location to have a letter show up on screen, that would allow for much faster processing than on modern bitmap displays.

Of course, there's also more latency when you start throwing in things like USB stacks instead of the PS2 connection, and several layers of handlers (device drivers, window systems, etc.) and more complex key code handling (compose keys, etc.).

lostwizard
Автор

this is really cool and helpful cause Im studying for my exam atm, thank you!

sonias
Автор

I always test if the computer is hanged if when i press the num lock key if the led responds or not

sajukkhar
Автор

On the PC, keyboard interrupts only occur with PS/2 keyboards. For USB keyboards the kernel has to poll the keyboard for key presses.

DrewWalton
Автор

Om modern PCs (Since PC/AT) the lights are handled by the computer. On the original IBM PC there were no lights and the interface was unidirectional. I had a clone keyboard that had lights and they were handled by the keyboard. The problem was that if the code for example numlock on (many calculator programs did) the lights got out of sync so I ended up covering the light.

okaro
Автор

So at what level is Ctrl-Alt-Del or local equivalent processed in modern computers? I seem to recall that in older PCs this was handled inside the keyboard, which was just one of the reasons that a PC would refuse to operate without a keyboard attached…

PhilBoswell