"Press [key] to ..." hints

kcds.ui.ActionHint adds a prompt to this player's screen, as the game's own "E Talk" prompts:

// client
kcds.ui.ActionHint.create(
  { key: 'primary_action', text: 'Ring the bell', mode: 'hold', holdDuration: 2 },
  () => {
    kcds.core.Events.toServer('ringBell');
  },
);

Keys: a hint sits on one of the game's controls: primary_action, attack_special, torch, companion_interaction, distract or jump. Or it can use script_action, a free key KCDS keeps for scripts (U). The newest hint on a control is the one shown.

An enabled hint takes over its key. The game's action on that key does not run, so E puts down no sack and starts no talk. The game's prompts on that key (Talk, Loot, Pickpocket behind a player) are not drawn next to it. A disabled hint takes nothing.

Presses: one press calls the handler once. A hint appearing while the key is still held waits for the next press, for example "Release" right after "Put in the pillory". kcds.world.World.addInteraction behaves the same.

A press and a hold on one key

Press hints and hold hints stack separately, so a key can have both, as the game's prompts do. The newest of each shows. Letting go before holdDuration runs the press hint, and a full hold runs the hold hint. E, X and the special attack key draw both. Other keys draw only the hold hint, but both still work.

// client
const { ActionHint } = kcds.ui;
const { Events } = kcds.core;

ActionHint.create({ key: 'companion_interaction', text: 'Untie' }, () => {
  Events.toServer('untie');
});
ActionHint.create(
  { key: 'companion_interaction', text: 'Lead on a rope', mode: 'hold', holdDuration: 1 },
  () => Events.toServer('lead'),
);

Drawing hints yourself

ActionHint.shown() lists all hints the HUD is drawing, including the game's prompts, as { key, map, text, mode, enabled, progress }, with text in the player's language. ActionHint.shownKeys() and ActionHint.isKeyInUse(key) tell which keys a hint is waiting on, and actionHintsChanged fires when the set changes. So a resource can hide the game's hints and draw its own:

// client
kcds.ui.Hud.setHudPart('Hints', false);

kcds.core.Events.on('actionHintsChanged', () => {
  console.log(JSON.stringify(kcds.ui.ActionHint.shown()));
});

While the player lies knocked out or fainted, the game's world hints, such as loot or picking up a body, are not drawn. Your hints and those of the pause screen still are.

kcds.ui.Web.anyFocused() says whether any resource's shown page has the keyboard and mouse. ActionHint.setText(id, text) changes a hint's text.

The server's own prompts on a place, a level entity or a body, the same for every player, are World.addInteraction (World).

Reference: ActionHint.