Keys: Difference between revisions
Jump to navigation
Jump to search
Line 1: | Line 1: | ||
== Overview == | == Overview == | ||
The [[Libreciva]] key function provides access to the | 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: | ||
< | <syntaxhighlight> | ||
#include "key.h" | #include "key.h" | ||
</ | </syntaxhighlight> | ||
=== struct key_handler *key_init() === | === struct key_handler *key_init() === | ||
This function must be called to | 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) === | === int key_poll(struct key_handler *eh, struct key *ev) === |
Revision as of 09:57, 31 December 2011
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>
- 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
#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) ; }