hi slzckboy,
To get the character value you first need to find the key code of that char. That depands on what platform you are using, key codes will vary from platform to platform.
here is some code to detect the different key codes:
getkey.c
Code:
#include <stdio.h>
#include "dtio.h"
int main(void){
int key;
char keystr[10];
dt_init();
dt_cursor(1,5);
dt_puts("Hit a key to get the key code. Q to exit");
key=dt_getchar();
while(key!='Q' && key!='q'){
dt_cursor(dt_rows()/2,dt_cols()/2-2);
sprintf(keystr,"%4d",key);
dt_puts(keystr);
key=dt_getchar();
}
dt_end();
}
dtio.c
Code:
#include "dtio.h"
#include <string.h>
#include <stdlib.h>
#if PLATFORM == AIX /*THIS WORKS ON LINUX TOO*/
#include <ncurses.h>
#else
#include <conio.h> /*FOR BORLAND*/
#endif
void dt_init(void){
#if PLATFORM == AIX
initscr();
noecho();
cbreak();
keypad(stdscr, 1);
#endif
}
void dt_end(void){
#if PLATFORM == AIX
refresh();
endwin();
#else
clrscr();
#endif
}
int dt_rows(void){
#if PLATFORM == AIX
return LINES;
#else
struct text_info x;
gettextinfo(&x);
return x.screenheight;
#endif
}
int dt_cols(void){
#if PLATFORM == AIX
return COLS;
#else
struct text_info x;
gettextinfo(&x);
return x.screenwidth;
#endif
}
void dt_clear(void){
#if PLATFORM == AIX
erase();
#else
clrscr();
#endif
}
void dt_flush(void){
#if PLATFORM == AIX
refresh();
#endif
}
void dt_cursor(int row,int col){
#if PLATFORM == AIX
move(row,col);
#else
gotoxy(col + 1, row + 1);
#endif
}
int dt_getchar(void){
#if PLATFORM == AIX
refresh();
return getch();
#else
int key;
key =getch();
return key==0? 1000+getch() :key;
#endif
}
void dt_putchar(int c){
#if PLATFORM == AIX
addch(c);
#else
putch(c);
#endif
}
void dt_puts(const char* s){
#if PLATFORM == AIX
addstr(s);
#else
cputs(s);
#endif
}
void dio_draw(char *str, int row, int col, int length){
}
int dio_edit(char* str, int slen, int row, int col,
int flen, int* start, int* offset, int* insert ){
}
dtio.h - specify here what platform you want and populate the key macro with the key codes you found
Now you can use this header file in your real application and appropriate keys should be triggered.
Code:
#define AIX 1
#define BORLAND 2
#define PLATFORM AIX
#if PLATFORM == AIX
#define LEFT 260 /*add in key code value*/
#define RIGHT 261
#define HOME 262
#define END 360
#define INS 331
#define DEL 330
#define BACK 263
#define PGUP 339
#define UP 259
#define DOWN 258
#define PGDOWN 338
#define ENTER 10
#define TAB 9
#define ESC 27
#else
#define LEFT
#define RIGHT
#define HOME
#define END
#define INS
#define DEL
#define BACK
#define PGUP
#define UP
#define DOWN
#define PGDOWN
#define ENTER
#define TAB
#define ESC
#endif
void dt_init(void);
void dt_end(void);
int dt_rows(void);
int dt_cols(void);
void dt_clear(void);
void dt_flush(void);
void dt_cursor(int row,int col);
int dt_getchar(void);
void dt_putchar(int c);
void dt_puts(const char* s);
void dio_draw(char *str, int row, int col, int length);
int dio_edit(char* str, int slen, int row, int col, int flen,
int* start, int* offset, int* insert );
Your real app what you have
Code:
#include "dtio.h"
int keycode=dt_getchar();
switch(keycode){
case LEFT:
case RIGHT:
case HOME:
...
}
I compiled this on linux and therefore these keycodes you see are for that platform you can double check them
cc dtio.c getkey.c -lncurses