#ifndef KEYS_H_INCLUDED
#define KEYS_H_INCLUDED

#include <stdint.h>

// Synthesised keypresses: drive RISC OS key up/down events from a joystick's
// mapped buttons and axis directions, injected via KeyV (OS_CallAVector),
// exactly the way USBDriver's real USB keyboard does - see doc.MouseKeyboard,
// "Keyboard synthesis". The configured key codes are RISC OS internal KeyNo
// values (Global/Keyboard.h), used directly as R1 to KeyV; no HID-usage
// translation is involved (unlike USBDriver), since our config stores KeyNo
// values, not HID usages.
//
// A joystick generates keys whenever it is active and has key mappings,
// independently of and in addition to any real keyboard - just as the mouse
// side sits alongside a real mouse.

// Reset all per-slot held-key state. Call once at module init (static
// storage would otherwise start as 0, which is a valid KeyNo, not "none").
void keys_init(void);

// Recompute the desired key state for one slot from its live buttons/axes and
// emit KeyV up/down events on any change. Called each decode from
// joystick_decode.
void update_keys(uint32_t slot);

// Release every key this slot currently holds down (send KeyV KeyUp), so keys
// don't stick when the device detaches or the module dies. Call from
// joy_remove_device and module_finalise.
void release_keys(uint32_t slot);

#endif
