2

I know that keyboard is standard input and is referred by the stdin file.

I sometimes use a Bluetooth(BT) keyboard when working on my laptop. Both keyboards, my laptop keyboard as well as the BT keyboard work simultaneously.

So, are both keyboards associated with stdin? If yes, how are they synchronized?

2

A keyboard is just an input device, it has no direct relation to standard input as such. The standard input of a program is merely an abstract data stream that is passed as file descriptor 0.

Many programs using standard input take input from the keyboard, but they don't do this directly. Instead, in the absence of instructions to do otherwise, your shell connects the new program's standard input to your terminal, which is connected to your keyboard. That the input comes from the keyboard is not any concern of the program, which just sees a stream of data coming from your terminal.

As for how both keyboards work simultaneously, this work is typically performed at the kernel level, not at the terminal or application level. Applications can either request to get input from one of the keyboards, or a mux of all of them. This representation typically applies to most human input devices, not just keyboards.

If you are using X, or a similar intermediate layer(s) between the kernel and your program, more abstractions may be present, but the basic idea is the same—utility applications typically don't access the keyboard.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.