Keys: Difference between revisions
Jump to navigation
Jump to search
(New page: == Overview == The libreciva key function provides access to the reciva keyboard. In order to use the library function, you must include the header file: <pre> #include "key.h" </pre> ...) |
|||
Line 64: | Line 64: | ||
struct key_handler *h ; | struct key_handler *h ; | ||
/* initialise / open the keyboard */ | |||
h=key_init() ; | h=key_init() ; | ||
if (h==NULL) exit(1) ; | if (h==NULL) exit(1) ; | ||
/* wait for a key change */ | |||
while (!key_poll(h, &k)) ; | while (!key_poll(h, &k)) ; | ||
/* finally, report what happened */ | |||
printf("Key State = %d, Key ID = %d | printf("Key State = %d, Key ID = %d | ||
", k.state, k.id) ; | ", k.state, k.id) ; | ||
} | } | ||
</pre> | </pre> |
Revision as of 21:22, 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) ; }