Keys

From Sharpfin
Jump to: navigation, search

Overview

The Libreciva key function provides access to the Reciva keyboard.

In order to use the library function, you must include the header file:

<syntaxhighlight>

  1. include "key.h"

</syntaxhighlight>

struct key_handler *key_init()

This function must be called to initialize the keyboard interface. It returns a handle structure, which must be used whenever the keyboard is polled with key_poll().

int key_poll(struct key_handler *eh, struct key *ev)

This function polls the keyboard, and returns:

  • -1 - There has been a problem with the key interface
  • 0 - No key events are queued
  • 1 - Key event has occurred

When the function returns '1', the key structure is updated to contain details of the selected key.

<syntaxhighlight> struct key {

 enum key_state state;
 enum key_id id;

} </syntaxhighlight>

The state is one of the following:

  • KEY_STATE_PRESSED
  • KEY_STATE_RELEASED

The id is one of the following:

  • KEY_ID_1
  • KEY_ID_2
  • KEY_ID_3
  • KEY_ID_4
  • KEY_ID_5
  • KEY_ID_SHIFT
  • KEY_ID_BACK
  • KEY_ID_SELECT
  • KEY_ID_REPLY
  • KEY_ID_POWER
  • KEY_ID_LEFT
  • KEY_ID_RIGHT
  • KEY_ID_VOLUP
  • KEY_ID_VOLDN
  • KEY_ID_BROWSE

Example

<syntaxhighlight>

  1. include "key.h"
  2. include <stdio.h>

main() {

 struct key k;
 struct key_handler *h;
 /* initialise / open the keyboard */
 h=key_init();
 if (h==NULL) exit(1);
 /* wait for a key change */
 while (!key_poll(h, &k));
 /* finally, report what happened */
 printf("Key State = %d, Key ID = %d

", k.state, k.id); } </syntaxhighlight>