libnds
Data Structures | Typedefs | Enumerations | Functions
keyboard.h File Reference

nds stdio keyboard integration. More...

#include <nds/ndstypes.h>
#include <nds/arm9/background.h>

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 for a key changed.
 
typedef struct KeyMap KeyMap
 defines a key mapping.
 

Enumerations

Functions

KeyboardkeyboardDemoInit (void)
 initializes the keyboard with default options. Same as calling keyboardInit(NULL, 3, BgType_Text4bpp, BgSize_T_256x512, 20, 0, false, true) More...
 
int keyboardGetChar (void)
 Waits for user to press a key and returns the key pressed. Use keyboardUpdate instead for async operation.
 
KeyboardkeyboardGetDefault (void)
 Gets the default keyboard.
 
int 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. More...
 
void keyboardGetString (char *buffer, int maxLen)
 reads the input until a the return key is pressed or the maxLen is exceeded. More...
 
void keyboardHide (void)
 Hides the keyboard.
 
KeyboardkeyboardInit (Keyboard *keyboard, int layer, BgType type, BgSize size, int mapBase, int tileBase, bool mainDisplay, bool loadGraphics)
 initializes the keyboard system with the supplied keyboard More...
 
void keyboardShow (void)
 Displays the keyboard.
 
int keyboardUpdate (void)
 Processes the keyboard. Should be called once per frame when using the keyboard in an async manner. More...
 

Detailed Description

nds stdio keyboard integration.

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 40KiB of background vram begining at tile base 1 and 2KB of map stored at map base 30. The default is designed to function along side a default instance of the console print functionality.
To customize keyboard behavior and resource usage modify the keyboard structure returned by keyboardGetDefault() or create your own keyboard.

Enumeration Type Documentation

States the keyboard can be in, currently only Lower and Upper supported.

Enumerator
Lower 

Normal keyboard display (lowercase letters)

Upper 

Caps lock Held

Numeric 

Numeric only keypad (not provided by the default keyboard)

Reduced 

Reduced footprint keyboard (not provided by the default keyboard)

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.

Enumerator
NOKEY 

will be returned if no key was pressed.

DVK_FOLD 

will be returned if the fold key was pressed (topleft on the default keyboard).

DVK_TAB 

will be returned if the tab key was pressed.

DVK_BACKSPACE 

will be returned if the backspace key was pressed.

DVK_CAPS 

will be returned if the caps key was pressed.

DVK_SHIFT 

will be returned if the shift key was pressed.

DVK_SPACE 

will be returned if the space key was pressed.

DVK_MENU 

will be returned if the menu key was pressed.

DVK_ENTER 

will be returned if the enter key was pressed.

DVK_CTRL 

will be returned if the ctrl key was pressed.

DVK_UP 

will be returned if the up key was pressed.

DVK_RIGHT 

will be returned if the right key was pressed.

DVK_DOWN 

will be returned if the down key was pressed.

DVK_LEFT 

will be returned if the left key was pressed.

DVK_ALT 

will be returned if the alt key was pressed.

Function Documentation

Keyboard* keyboardDemoInit ( void  )

initializes the keyboard with default options. Same as calling keyboardInit(NULL, 3, BgType_Text4bpp, BgSize_T_256x512, 20, 0, false, true)

Returns
a pointer to the current keyboard.
int 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.

Parameters
xthe pixel x location
ythe pixel y location
Returns
the key pressed or NOKEY if user pressed outside the keypad
void keyboardGetString ( char *  buffer,
int  maxLen 
)

reads the input until a the return key is pressed or the maxLen is exceeded.

Parameters
buffera buffer to hold the input string
maxLenthe maximum length to read
Keyboard* keyboardInit ( Keyboard keyboard,
int  layer,
BgType  type,
BgSize  size,
int  mapBase,
int  tileBase,
bool  mainDisplay,
bool  loadGraphics 
)

initializes the keyboard system with the supplied keyboard

Parameters
keyboardthe keyboard struct to initialize (can be NULL)
layerthe background layer to use
typethe background type to initialize
sizethe background size to initialize
mapBasethe map base to use for the background
tileBasethe graphics tile base to use for the background
mainDisplayif true the keyboard will render on the main display
loadGraphicsif true the keyboard graphics will be loaded
Returns
returns the initialized keyboard struct
int keyboardUpdate ( void  )

Processes the keyboard. Should be called once per frame when using the keyboard in an async manner.

Returns
the ascii code of the key pressed or -1 if no key was pressed.