Keys: Difference between revisions
Jump to navigation
Jump to search
Created page with "== 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..." |
No edit summary |
||
| Line 5: | Line 5: | ||
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: | ||
< | <pre> | ||
#include "key.h" | #include "key.h" | ||
</ | </pre> | ||
=== struct key_handler *key_init() === | === struct key_handler *key_init() === | ||
| Line 23: | Line 23: | ||
When the function returns '1', the key structure is updated to contain details of the selected key. | When the function returns '1', the key structure is updated to contain details of the selected key. | ||
< | <pre> | ||
struct key { | struct key { | ||
enum key_state state; | enum key_state state; | ||
enum key_id id; | enum key_id id; | ||
} | } | ||
</ | </pre> | ||
The '''state''' is one of the following: | The '''state''' is one of the following: | ||
| Line 55: | Line 55: | ||
== Example == | == Example == | ||
< | <pre> | ||
#include "key.h" | #include "key.h" | ||
#include <stdio.h> | #include <stdio.h> | ||
| Line 71: | Line 71: | ||
/* finally, report what happened */ | /* 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> | ||
Latest revision as of 13:18, 8 June 2025
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 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.
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);
}