Keys: Difference between revisions

From Sharpfin
Jump to navigation Jump to search
Line 1: Line 1:
== Overview ==
== Overview ==


The libreciva key function provides access to the reciva keyboard.
The [[Libreciva]] key function provides access to the reciva keyboard.


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

Revision as of 21:59, 17 September 2007

Overview

The Libreciva key function provides access to the reciva keyboard.

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

#include "key.h"

struct key_handler *key_init()

This function must be called to initialise 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.

struct key {
  enum key_state state ;
  enum key_id id ;
}

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

#include "key.h"
#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) ;
}