Le but de ce programme est de donner un outil simple permettant d'obtenir rapidement les différents codes (sym et unicode) et les différents modes du clavier lorsque l'on appuie sur une touche du clavier.
Le code source suivant ne constitue pas un tutoriel.
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#include <stdio.h>
#if defined( __WIN32__ ) || defined( _WIN32 ) || defined( __CYGWIN__ )
extern int asprintf (char **, const char *, ...);
#endif
#include <stdlib.h>
#include <string.h>
void draw_sentence( int width, int height ){
10, 50,
"Appuyez sur une touche pour connaître :\n - son code,\n - son mode,\n - son code unicode,\n - le caractère qui lui est associé.",
3,
);
}
int main( int argc, char *argv[] ){
int width = 640;
int height = 480;
MLV_create_window(
"beginner - 10 - Le code des touches du clavier",
"codes - touches du clavier", width, height );
draw_sentence( width, height );
const char* sym_string;
char* mod_string;
int unicode;
char* character;
char* text;
while( 1 ){
if(
asprintf(
&text,
"Information sur la touche:\n-------------------------\nSym : %s \nMod : %s \nUnicode : %d \nCaractère : %s \n\n",
sym_string, mod_string, unicode, character
) == -1
){
fprintf( stderr, "Allocation Error - file : %s, line : %d \n", __FILE__, __LINE__);
exit(1);
};
printf( "%s", text );
draw_sentence( width, height );
10, 160, text, 6,
);
free( character );
free( mod_string );
free( text );
}
return 0;
}