User:Cboomf/libusbkbd

From WiiBrew
Jump to: navigation, search

Provides a simple way to add usb keybard support to any app.

Currently in on release v1.

It is designed to be lightweight and be simple to use for beginner/novice dev's. Do don't expect a great deal of control, for more experienced dev's use : Libwiikeyboard by davyg

Readme

For sourced version : just copy kbd.c and kbd.h to your sourced folder, then include kbd.h using

                            #include "kbd.h"

For .a lib version  : copy libusbkbd.a to DEVKITPRO path/libogc/lib/wii and copy kbd.h to DEVKITPRO path/libogc/include, then include kbd.h using

#include <kbd.h>

Download

v1 as sources: File:Libusbkbd.rar
Notes : Requires the keyboard to be plugged in prior to launch when used

v1 as a .a lib: File:Libusbkbdlib.rar
Notes : Requires the keyboard to be plugged in prior to launch when used

Demo : File:Kbd.rar
Notes : Requires the keyboard to be plugged in prior to launch

Documentation

To use, include kbd.h into the source file then use the functions below use

Functions

char* kbdhandle(int fd, char message[15], bool output);  //Returns the pressed key
int kbdinit();                                           //Inits the library
void kbddeinit(int kbdfd);                               //Closes the library
char* kbdscan(int kbdfd);                                //Scans for keypresses
int kbdver();                                            //Returns the library version

kbdver(); = returns the lib version
kbdinit(); = inits the lib and returns the keyboard fd handle
kbdscan(); = similar to WPAD_Scan(); but returns the raw message from the kbd, must be passed what kbd returned
kbdhandle(); = returns the charachter or code of what was pressed, fd is what kbdinit returned, message is what kbdscan returns, output is whether you want the full breakdown of the message
kbddeinit(); = closes the library, must be done before exit(0); or similar, must be passed what kbdinit returned

Examples :

int kbdfd = kbdinit();
char receivedmessage[15] = kbdscan(kbdfd);
char* pressed = kbdhandle(kbdfd, receivedmessage, false);
printf("%s was pressed\n", pressed);
kbddeinit(kbdfd);

Or more complicated :

int kbdfd = kbdinit();
printf("%s was pressed\n",kbdhandle(kbdfd,kbdscan(kbdfd), false);
kbddeinit(kbdfd);