The most basic operation in working with a keyboard layout is editing key output. What this means is changing what a particular key will produce when it is typed. That will depend on the current modifiers and the current dead key state.

There are three different ways to change a key’s output:
Drag and drop
Clicking the key
Choosing the key by its key code

In all cases, the current state of the modifiers and dead key state are taken into account. For drag and drop, clicking or pressing, it is whatever modifier keys were down when you dropped the text or clicked or pressed the key. For choosing it by key code, it is the current modifiers, which are set when the command is chosen, or by having sticky modifiers on.