One-handed keyboard on the cheap

The Belkin Nostromo n52 Speedpad has 14 typewriter-style keys that chord (meaning they can all be read individually), LEDs, a dial, and a game controller with firing button. That's easily enough to make a chording keyboard. You can use the game controller as four shift keys (your thumb rests upon it).

To make the job easier, here's C code to read the device on Linux. To finish the job, you'll also have to push key events back into the Linux console or X Windows. Code to do that is already available on the net, it's been written for use with other USB devices.
/* Copyright 2003 Bruce Perens.
You may use this software under
the BSD license without the
advertising clause. */
#include
#include
#include
#include
#include
#include

struct chord_context {
unsigned int pressed;
unsigned int first_release;
};

static const char keyboard_device[] = "/dev/input/event0";
unsigned int key_base = 304;

void
character(unsigned int code)
{
printf("%xn", code);
fflush(stdout);
}

void
key(int code, int pressed, struct chord_context * context)
{
if ( pressed ) {
context->first_release = 1;
context->pressed |= 1 < < (code - key_base);
}
else {
if ( context->first_release ) {
context->first_release = 0;
character(context->pressed);
fflush(stdout);
}
context->pressed &= ~(1 << (code - key_base));
}
}

int
main()
{
struct input_event event;
struct chord_context context;
int fd;
int size;

fd = open(keyboard_device, O_RDWR, 0);

if ( fd < 0 ) {
perror(keyboard_device);
exit(1);
}

memset(&context, 0, sizeof(context));

while ( (size = read(fd, &event, sizeof(event)))
== sizeof(event) ) {
if ( event.type == EV_KEY )
key(event.code, event.value, &context);
}
return 0;

About this article

written on
posted in General Back to Top

About the Author

Andrew Turner is an advocate of open standards and open data. He is actively involved in many organizations developing and supporting open standards, including OpenStreetMap, Open Geospatial Consortium, Open Web Foundation, OSGeo, and the World Wide Web Consortium. He co-founded CrisisCommons, a community of volunteers that, in coordination with government agencies and disaster response groups, build technology tools to help people in need during and after a crisis such as an earthquake, tsunami, tornado, hurricane, flood, or wildfire.