'Understanding how keyboard input interfaces with the OS and user processes

When keyboard input is sent to the keyboard controller on the motherboard, which in turn creates a hardware interrupt and thus a context switch, what exactly does the operating system do with it at this point (I'm assuming this is when the device driver handler is run)?

  1. After the interrupt, does the OS store the input in some data structure (like a queue) in a dedicated RAM location for which processes can later read from, or do applications (like game engines) simply read directly from the device (USB/Host) controller itself via low-level OS commands?

Furthermore, if I have a game with the following input handler function...

handleInput (Event e) {
   if (e.keyPressed && e.value == "W") {
      player.setVelocityY = 10;
   }
   if (e.keyReleased && e.value == "W") {
      player.setVelocityY = 0;
   }
   if (e.keyPressed && e.value == "C") {
      player.startAttack();
   }
   if (e.keyReleased && e.value == "C") {
      player.stopAttack();
   }
}
  1. Is the OS ever able to "fetch" more than one input value at any given time? What if I wanted to both set velocity and start an attack within the same frame (a single game loop cycle). I'm assuming the engine would have to be able to set "Event e" to an array of values instead of just a single value, which might only be possible if the interrupts are saving the individual values to a queue data structure in memory somewhere to be read from later?

  2. If it is the case that game engines can only process a single input value at a time (one event per game cycle/frame) and I have the following queue (given I have super fast fingers and can press all of these before the next game loop cycle)...

[{"W", "Pressed"}, {"W", "Released"}, {"W", "Pressed"}, {"W", "Released"}, {"C", "Pressed"}, {"C", "Released"}]

Wouldn't my game have to wait until frame #5 until the attack start command was processed? This seems undesirable?

Any insight is greatly appreciated, thanks!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source