: input.ayaan — edge-triggered key detection
:
: gui_key_down returns 1 every frame a key is held. Often you want "fired
: exactly when the key transitions from up to down" (e.g. menu navigation,
: jumping). This module tracks previous frame state per key in a dict.

dict __gt_key_prev

: Returns 1 ONLY on the frame the key was just pressed.
func key_pressed key
    gui_key_down key -> cur
    dget __gt_key_prev key -> prev
    set result = 0
    if cur == 1
        if prev != 1
            set result = 1
        endif
    endif
    dset __gt_key_prev key cur
endfunc

: Returns 1 ONLY on the frame the key was just released.
func key_released key
    gui_key_down key -> cur
    dget __gt_key_prev key -> prev
    set result = 0
    if cur != 1
        if prev == 1
            set result = 1
        endif
    endif
    dset __gt_key_prev key cur
endfunc

: Returns 1 if key is currently held.
func key_held key
    gui_key_down key -> cur
    set result = cur
endfunc
