Skip to main content

How input works

The interface · The play screen · Camp menus · The game loop

In brief​

The keyboard and the mouse put their events into one queue, and each pass of the game loop takes one event from it. A key or a mouse press is offered to the buttons of the active list, in order, until one of them ends the walk; a key that no button takes goes on to the keyboard commands. Whether the game is in mouse control or keyboard control decides whether clicks count, whether a pointer is drawn and which item counts as held.

How the game handles input. A key press or a mouse press joins a queue; Alt+S and Alt+M act as they are queued. Each pass of the game loop reads one event and walks the active button list in order: a button whose key matches, or under a press of a mouse button it answers to, runs its action; an action that returns 0 lets the walk go on, any other value ends it. A key that no button takes reaches the keyboard commands, which act only in keyboard control.
A click can pass through several buttons; a key no button takes goes on to the keyboard commands.

Keys and mouse presses​

The keyboard and mouse handlers put each event into one queue, in the order they happen: a key press as a key number with bits for Shift, Ctrl and Alt, a press or release of either mouse button with the position of the pointer. Key releases are not queued. The grey arrows and the other grey keys give the numbers of the matching keypad keys, and keypad Enter that of Enter, so what the pages of this chapter say of a keypad key also holds for its grey key. These keys never get the Shift bit.1

Two hot keys act as the key is queued, on any screen: Alt+S switches the "Sounds" option and Alt+M the "Tunes" option.1

Bug

ANOMALY-135 — With Caps Lock on, the keyboard handler should add Shift to a letter key, and with Num Lock on to a keypad key. It tests the key against its table with a processor register it never sets, so whether a key gets Shift depends on the value left in that register by the code the key press interrupted. The text fields turn letters into capitals, so the visible effect is unknown. A faithful reimplementation cannot reproduce the exact value; it may treat the result as unpredictable.2

Mouse control and keyboard control​

The start-up decides how the game is played. It is in keyboard control when no mouse was detected or when the setup program was told not to use one, and in mouse control otherwise. The keys of the buttons work in both.3

Mouse controlKeyboard control
PointerDrawn, shows the held itemNot drawn
ClicksAct on the buttons under the pointerIgnored by the buttons and the slot menus
Held itemThe item on the pointerThe item in the selected hand or slot of the selected character
Keyboard commandsDo nothingW, S, Z, A, U, D, T, G and M act
Highlight in menusFollows the pointerMoved by keys only

The active button list​

A button has a rectangle, up to two keys, the mouse buttons it answers to, a number and usually an action. The buttons of the play screen are not drawn: what the player sees there is the screen picture.4

Each pass of the game loop reads at most one event from the queue. A letter key loses its Shift bit first, so it reads the same with or without Shift; other keys keep it, which is how Shift+F1 differs from F1. The list is then walked in order, and for each button:4

  1. a key triggers the button when it is one of the button's two keys;
  2. in mouse control, a press inside the rectangle triggers the button when it answers to that mouse button. Every button answers to either one, except the name strips, which answer only to the right button;
  3. a triggered button runs its action at once. An action can tell whether a click or which of the two keys triggered it. When it returns 0, the walk goes on to the next button; otherwise the walk ends.

A key that triggers no button goes back to the caller; on the play screen it then reaches the keyboard commands.

The list depends on the situation:5

SituationButtons, in order
Play screenWall in front, character boxes, camp, floor, faces, hands, names, arrows, throw
Character panel, inventory pageWall in front, 27 slots, plate, page, close, next, previous, a button for F5 and F6, then camp, floor, arrows, throw
Character panel, character sheetThe same without the slots and the plate
Spell book openWall in front, the book's buttons, then the rest of the play screen list
Spell book open with the panelWall in front, tabs, six lines, ABORT SPELL, then the panel's list. The page arrows and the keys ,, . and Space have no button here
Swap or spell targetSix characters and a button that cancels
MenusThe buttons of the menu

The pointer and the item it carries​

In mouse control the pointer starts as item icon 0, cut from ITEMICN.CPS, with its hot spot at the top-left corner. When an item is taken, the pointer becomes that item's icon, with its hot spot at the centre of the 16 × 16 icon; while the party has SPELL_EFFECT_DETECT_MAGIC, a magical item shows in other colours. Giving up the item brings icon 0 back.6

The player carries one item at a time. What a click does with it depends on the area: see moving and equipping items, items on the floor and throwing. The game hides the pointer while it draws under it, and during text input.

Sources​

Locations refer to the game executable reference; comparative sources are listed in the technical references.

Footnotes​

  1. Keyboard and mouse-button handlers, which carry the key numbers and hot keys, the input queue, the option settings. ↩ ↩2

  2. Keyboard and mouse-button handlers and read a key as a character. ↩

  3. The mouse and control state, with the mouse initialization, keyboard command dispatch, process the button list, the held item and the mouse pointer. ↩

  4. Key reader, process the button list, which gives the fields of a button, the button trigger, draw a button and swap two characters for the right button. Comparative source: REF-SCUMM-014, runLoop. ↩ ↩2

  5. The active button list, with build the main button list, the character-choice lists, the panel state and build and show a menu. The panel and book lists and the areas of their buttons are read from the button records of the executable's data image, through the arrays that these entries name. ↩

  6. Load the item icons and set the pointer, give the held item, which sets the shape and hot spot, the mouse pointer routines, the item held with the mouse and edit a text field. ↩