How does the delete key actually delete stuff

A short tutorial on how to compile R for beginners
Bash
Tutorial
Author

Gninahophin Jean-Pierre Axel

A beautiful afternoon ravaged by curiosity

It was a beautiful afternoon, I had been coding for awhile, implementing what I was thinking about with no difficulties. I ended up reading in the documentation of VIM for whatever reason. And while doing so, I learned that I could type CTRL-H in insert mode to delete the key before my cursor. How cool ,right ?!

And then I tried it bash,zsh and fish … and it still worked ?

And I know my emacs friends are making fun of me right now. Of course, this is a well-know gnu readline shortcuts.

But this sparkled an even deeper interest. This shortcut essentially emulates the delete key right ? But why does the delete key actually delete ? This is the kind of toddler questions that can keep you up at night because chances are if you don’t have a lot of experience with low level programming you actually don’t know , right ? You’ve been taking the fact that when you type on your keyboards , some keys magically appears on your screen , some disappear, and for some reason you can even type non ascci keys despite the fact that there’s probably none on your keyboard. And this… is the start of my big adventure to figure out how my keyboard actually works on Linux.

Everything is a file

If you’ve been in the Linux community for long enough, you’ve probably already heard this before. And as far my knowledge goes which is arguably not that far, it’s true most of the time as long as you’re flexible about what is a file.

In your /dev/input/ directory you have a list of such files … typically called \(event_i,i \in \mathbb{N}\)

ls -l --time-style=+"" /dev/input/*

If you look at the end of the output you can see platform-i8042-serio-0-event-kbd -> ../event0

This tell us that my keyboard is “mapped” to the event0 file. Let’s use a little bit of abstraction here to keep it simple. The Linux kernel(ft the devices drivers) detected my hardware correctly. For each devices detected that can provide an input it will create a file in /dev/input. The udev daemon will populate them as they receive inputs .

You can actually monitor this file and it makes for a pretty fun experiment.

Just sudo cat the event file for your mouse/keyboard and move one/type on the other !

You can find more details on how to process the stream you’re seeing on this other nice blog post.

Happy hacking !