|
libnds
|
Integration of stdin with a simple keyboard. More...
Data Structures | |
| struct | Keyboard |
| Describes a keyboard. More... | |
| struct | KeyMap |
| Defines a key mapping. More... | |
Typedefs | |
| typedef struct Keyboard | Keyboard |
| Describes a keyboard. | |
| typedef void(* | KeyChangeCallback) (int key) |
| Callback function pointer when a key changes. | |
| typedef struct KeyMap | KeyMap |
| Defines a key mapping. | |
| typedef void(* | KeyPutcCallback) (int) |
| Callback used when libnds wants to push characters to the stdin FIFO. | |
| typedef int(* | KeyUpdateCallback) (void) |
| Callback to handle touch screen press/release events. | |
Enumerations | |
| enum | KeyboardModifierMode { KeyboardModifiersIgnore , KeyboardModifiersStickOnce , KeyboardModifiersStickAlways } |
| Modes of handling CTRL and ALT buttons. More... | |
| enum | KeyboardState { Lower = 0 , Upper = 1 , Numeric = 2 , Reduced = 3 } |
| States the keyboard can be in, currently only Lower and Upper supported. More... | |
| enum | Keys { NOKEY = -1 , DVK_FOLD = -23 , DVK_TAB = '\t' , DVK_BACKSPACE = '\b' , DVK_CAPS = -15 , DVK_SHIFT = -14 , DVK_SPACE = ' ' , DVK_MENU = -5 , DVK_ENTER = '\n' , DVK_CTRL = -16 , DVK_UP = -17 , DVK_RIGHT = -18 , DVK_DOWN = -19 , DVK_LEFT = -20 , DVK_ALT = -26 } |
| Enum values for the keyboard control keys. More... | |
Functions | |
| Keyboard * | keyboardDemoInit (void) |
| Initializes the default keyboard of libnds. | |
| void | keyboardExit (void) |
| De-initializes the keyboard system, if initialized. | |
| int | keyboardFifoGetc (void) |
| Fetches the first character available from the keyboard FIFO. | |
| int | keyboardFifoPutc (char kc) |
| Manually add a character to the keyboard FIFO. | |
| void | keyboardFifoStart (void) |
| Initializes the keyboard FIFO. | |
| size_t | keyboardFifoStoredCharacters (void) |
| Returns the number of characters currently available in the keyboard FIFO. | |
| int | keyboardFifoUnputc (void) |
| Try to remove the last character pushed to the keyboard FIFO. | |
| void | keyboardFifoUpdate (void) |
| Checks the state of the keyboard and saves key presses in the FIFO buffer. | |
| s16 | keyboardGetChar (void) |
| Waits for user to press a key and returns the key pressed. | |
| const Keyboard * | keyboardGetDefault (void) |
| Gets the default keyboard. | |
| s16 | keyboardGetKey (int x, int y) |
| Returns the ASCII code for the key located at the supplied x and y. | |
| void | keyboardGetString (char *buffer, int maxLen) |
| Reads the input until a the return key is pressed or the maxLen is exceeded. | |
| void | keyboardHide (void) |
| Hides the keyboard. | |
| static Keyboard * | keyboardInit (const Keyboard *keyboard, int layer, BgType type, BgSize size, int mapBase, int tileBase, bool mainDisplay, bool loadGraphics) |
| Initializes the keyboard system with the supplied keyboard. | |
| bool | keyboardIsVisible (void) |
| Check if the active keyboard is visible or not. | |
| int | keyboardModifierModeSet (KeyboardModifierMode mode) |
| Changes the behaviour of the CTRL and ALT keys of the current keyboard. | |
| void | keyboardShow (void) |
| Displays the keyboard. | |
| s16 | keyboardUpdate (void) |
| Processes the keyboard. | |
Integration of stdin with a simple keyboard.
The keyboard component allows the use of a default keyboard via stdin as well as direct via the functions exposed below. The default behavior is a hidden keyboard that shows on a call to scanf(stdin, ...).
By default the keyboard uses background 3 of the sub display, consumes approximatly 40 KiB of background VRAM begining at tile base 0 and 4 KiB of map stored at map base 20. The default is designed to work alongside an instance of the demo console.
To customize keyboard behavior and resource usage modify the keyboard structure returned by keyboardGetDefault() or create your own keyboard.
| enum KeyboardModifierMode |
Modes of handling CTRL and ALT buttons.
| enum KeyboardState |
| enum Keys |
Enum values for the keyboard control keys.
Negative values are keys with no sensible ASCII representation. Numbers are chosen to mimic ASCII control sequences.
| Keyboard * keyboardDemoInit | ( | void | ) |
Initializes the default keyboard of libnds.
Same as calling:
| void keyboardExit | ( | void | ) |
De-initializes the keyboard system, if initialized.
After calling this function you'll need to call keyboardInit() again to use the keyboard, so it is safe to free any struct that you may have allocated (for example, if you're using a custom keyboard).
| int keyboardFifoGetc | ( | void | ) |
Fetches the first character available from the keyboard FIFO.
This can be useful when using a custom keyboard, but not using OS functions like read().
| int keyboardFifoPutc | ( | char | kc | ) |
Manually add a character to the keyboard FIFO.
This can be useful when simulating keyboard input.
A keyboard must be initialized before using this function. If you want to use a completely custom keyboard (not the libnds one) you need to call keyboardFifoStart() before using this.
| kc | The character to add to the FIFO. |
| size_t keyboardFifoStoredCharacters | ( | void | ) |
Returns the number of characters currently available in the keyboard FIFO.
| int keyboardFifoUnputc | ( | void | ) |
Try to remove the last character pushed to the keyboard FIFO.
This only works while there are entries in the FIFO. If they have been read already, this function does nothing.
| void keyboardFifoUpdate | ( | void | ) |
Checks the state of the keyboard and saves key presses in the FIFO buffer.
If your application wants to do non-blocking reads of stdin it must regularly call this function so that key presses are registered and stored in the input FIFO buffer. You must call scanKeys() regularly as well.
This is only needed if you want to use the standard syscalls read(), ioctl() and fcntl() to access keyboard input. For example, this can be very useful if you're porting applications to the DS. If you are creating a new DS-specific application, use keyboardUpdate() instead, which is more efficient.
A keyboard must be initialized before using this function. If you want to use a completely custom keyboard (not the libnds one) you need to call keyboardFifoStart() before using this.
You can also query the amount of characters in stdin available to be read;
| s16 keyboardGetChar | ( | void | ) |
Waits for user to press a key and returns the key pressed.
Use keyboardUpdate instead for async operation.
Remember to call scanKeys() every frame if you use keyboardGetChar().
| const Keyboard * keyboardGetDefault | ( | void | ) |
Gets the default keyboard.
| s16 keyboardGetKey | ( | int | x, |
| int | y | ||
| ) |
Returns the ASCII code for the key located at the supplied x and y.
Will not effect keyboard shift state.
| x | The pixel x location. |
| y | The pixel y location. |
| void keyboardGetString | ( | char * | buffer, |
| int | maxLen | ||
| ) |
Reads the input until a the return key is pressed or the maxLen is exceeded.
| buffer | A buffer to hold the input string |
| maxLen | The maximum length to read |
| void keyboardHide | ( | void | ) |
Hides the keyboard.
If scrollSpeed has been set to a non-zero value it will scroll it out of the screen. If not, it will hide it right away.
|
inlinestatic |
Initializes the keyboard system with the supplied keyboard.
| keyboard | The keyboard struct to initialize (can be NULL). |
| layer | The background layer to use. |
| type | The background type to initialize. |
| size | The background size to initialize. |
| mapBase | The map base to use for the background. |
| tileBase | The graphics tile base to use for the background. |
| mainDisplay | If true the keyboard will render on the main display. |
| loadGraphics | If true the keyboard graphics will be loaded. |
| bool keyboardIsVisible | ( | void | ) |
Check if the active keyboard is visible or not.
| int keyboardModifierModeSet | ( | KeyboardModifierMode | mode | ) |
Changes the behaviour of the CTRL and ALT keys of the current keyboard.
Normally the CTRL and ALT keys are treated like other keys. It is possible to make them "sticky" and remain pressed until another key is pressed or to make them remain pressed until they are pressed again, depending on what your application requires.
| mode | New mode to set. |
| void keyboardShow | ( | void | ) |
Displays the keyboard.
This will set the state of the keyboard to the original one (the one it had when the keyboard was initialized). If the default state of the keyboard is to show upper-case letters, this will return to that state.
| s16 keyboardUpdate | ( | void | ) |
Processes the keyboard.
Should be called once per frame when using the keyboard in an async manner.
Remember to call scanKeys() every frame if you use keyboardUpdate().