Here is a diagram that shows how keyboard input is handled. Each node that performs mapping has a label, optionally followed by the commands that change its mapping behavior.