void main() { int i; con_init(); while(1) { i = con_getkey(); printf("%d\n",i); con_update(); } }
void con_getline(char *buf, int length) { int index = 0; char ch = 0; // loop until we encounter a linefeed or carriage return, or until we run out of space while (!get_quitflag()) { ch = con_getkey(); // if we get a linefeed or carriage return, we're done ... if ((ch == 10) || (ch == 13)) { break; } // backspace, it works but it doesn't look pretty on the screen else if (ch == 8) { if (index >0) { index = index - 1; outstr("[BACK]"); } } // if we've run out of space, terminate the string prematurely to avoid crashing else if (index >= (length - 1)) { break; } // otherwise if we get a printable character, add it to the string else if (ch >= ' ') { outchr(ch); // echo it to the screen buf[index] = ch; index = index + 1; } // else it was a non-printable character, so we ignore it } buf[index] = 0; // terminate the string newline(); // go to the next line }
void drawmessagebox(char * string1, char * string2, int wait) { int width, startcolumn, row, i, padding1, padding2; if(strlen(string1) < strlen(string2)) { width = strlen(string2); if(width > (con_xsize - 6)) { width = con_xsize - 6; string2[width] = 0; } padding1 = width - strlen(string1); padding2 = 0; } else { width = strlen(string1); if(width > (con_xsize - 6)) { width = con_xsize - 6; string1[width] = 0; } padding1 = 0; padding2 = width - strlen(string2); } width = width+6; row = 10; startcolumn = (con_xsize - width)/2; con_gotoxy(startcolumn, row); putchar(' '); for(i = 0; i < width-2; i++) putchar('_'); putchar(' '); row++; con_gotoxy(startcolumn, row); putchar(' '); putchar('|'); for(i = 0; i < width-4; i++) putchar(' '); putchar('|'); putchar(' '); row++; con_gotoxy(startcolumn, row); putchar(' '); printf("| %s", string1); for(i=0; i<padding1; i++) putchar(' '); putchar(' '); putchar('|'); putchar(' '); row++; if(strlen(string2) > 0) { con_gotoxy(startcolumn, row); putchar(' '); printf("| %s", string2); for(i=0; i<padding2; i++) putchar(' '); putchar(' '); putchar('|'); putchar(' '); row++; } con_gotoxy(startcolumn, row); putchar(' '); putchar('|'); for(i = 0; i < width-4; i++) putchar('_'); putchar('|'); putchar(' '); row++; con_gotoxy(startcolumn, row); for(i = 0; i < width; i++) putchar(' '); con_update(); if(wait) con_getkey(); }