K here is the problem. I am just messing around developing for the Ipod using Ipod Linux. However the Ipod only has 8 keys. What this causes is that when the wheel is scrolled to the left the "l" key is pressed and when scrolled to the right the "r" key is called and when the center button is hit the "enter" key is called.
Now I would like to be able to let the user hit all the keys. I already have found someone that has made it so that you can hit the characters but it only receives one character. If someone could help me edit this function to take a full string it would be greatly appreciated. Also anyone that could make it so that I could turn the characters into corresponding integers would help even more.
Here is the code to get a single character.
Code:
// This function is used to get only one character.
int mygetch()
{
struct termios oldt, newt;
int ch;
tcgetattr( STDIN_FILENO, &oldt );
newt = oldt;
newt.c_lflag &= ~( ICANON | ECHO );
tcsetattr( STDIN_FILENO, TCSANOW, &newt );
ch = getchar();
tcsetattr( STDIN_FILENO, TCSANOW, &oldt );
return ch;
}
char getinput(char *charlist)
{
char input;
char flag;
char curfl = 0;
flag = charlist[curfl];
putc(flag, stdout);
while (1)
{
if (input = mygetch())
switch(input)
{
case 'r': // user rotated right, advance character.
if (curfl < strlen(charlist)-1)
{
putc(8, stdout);
curfl++;
flag = charlist[curfl];
putc(flag, stdout);
}
break;
case 'l': // user rotated left, reverse character.
if (curfl > 0)
{
putc(8, stdout);
curfl--;
flag = charlist[curfl];
putc(flag, stdout);
}
break;
case '\n': // select button
return flag;
break;
default: // any other character!
break;
}
}
}
Now heres the actual way the function is called hopefully someone could help me also take integers and hopefully more than one character:
Code:
char foo;
foo = getinput("abcdefghijklmnopqrstuvwxyz");