Emulation of H/w interaction

We want to learn how we can emulate H/w devices like Keyboard inputs/touch screen etc. Let say we have Windows OS, on that we have emulated Linux OS. When we enter some text via keypad or touch the screen (in case of touch device). Then how host OS (Windows, in this case) will emulate it w.r.t guest OS (in this case Linux) and do proper actions.

We want to learn basic of this (not specific to Windows/Linux) etc. In some cases we may get input from other H/w devices, so how we will emulate it. How the host OS interact with H/w and emulate that interaction w.r.t to guest OS or chip set.

If I can get some basic block diagram or architecture diagram then it will be helpful.