Documentation de la bibliothèque MLV-3.1.0

medium/11_keys_codes.c

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>
#include <MLV/MLV_all.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,
);
}
//
// Attention !
// Pour pouvoir compiler ce programme sous windows et sous macintosh,
// il faut, pour la déclaration du main, respecter strictement la syntaxe
// suivante :
//
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 ){
MLV_wait_keyboard( &sym, &mod, &unicode );
character = MLV_convert_unicode_to_string( unicode );
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;
}
/*
* This file is part of the MLV Library.
*
* Copyright (C) 2010-2014 Adrien Boussicault, Marc Zipstein
*
*
* This Library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This Library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this Library. If not, see <http://www.gnu.org/licenses/>.
*/
MLV_convert_keyboard_button_to_string
const char * MLV_convert_keyboard_button_to_string(MLV_Keyboard_button key_code)
Renvoie la chaîne de caractères correspondant au code de la touche passé en paramètre.
MLV_TEXT_LEFT
@ MLV_TEXT_LEFT
Definition: MLV_text.h:46
MLV_create_window
void MLV_create_window(const char *window_name, const char *icone_name, unsigned int width, unsigned int height)
Créé une fenêtre dont la taille, et les différents noms sont passés en paramètres.
MLV_Keyboard_button
MLV_Keyboard_button
Énumère l'ensemble des codes des touches du clavier.
Definition: MLV_keyboard.h:50
MLV_free_window
void MLV_free_window()
Ferme la fenêtre de la bibliothèque MLV.
MLV_update_window
void MLV_update_window()
Met à jour l'affichage de la fenêtre.
MLV_convert_keyboard_mod_to_string
char * MLV_convert_keyboard_mod_to_string(MLV_Keyboard_modifier keymod_code)
Renvoie la chaîne de caractères correspondant au mode du clavier passé en paramètre.
MLV_COLOR_GREEN
#define MLV_COLOR_GREEN
Definition: MLV_color.h:931
MLV_all.h
Fichier d'entête principal incluant tous les autres fichiers entêtes de la bibliothèque MLV.
MLV_clear_window
void MLV_clear_window(MLV_Color color)
Éfface la fenêtre et la remplace par un monochrome de la couleur donnée en paramètre.
MLV_draw_adapted_text_box
void MLV_draw_adapted_text_box(int x, int y, const char *message, int sizeInterligne, MLV_Color borderColor, MLV_Color textColor, MLV_Color backgroundColor, MLV_Text_justification text_justification,...)
Dessine une boîte contenant du texte.
MLV_convert_unicode_to_string
char * MLV_convert_unicode_to_string(int unicode)
Transforme un caractère en format unicode en chaîne de caractères compatible avec le codage local (co...
MLV_Keyboard_modifier
MLV_Keyboard_modifier
Énumère l'ensemble des codes associées aux différents modes du clavier.
Definition: MLV_keyboard.h:299
MLV_COLOR_BLACK
#define MLV_COLOR_BLACK
Definition: MLV_color.h:379
MLV_wait_keyboard
void MLV_wait_keyboard(MLV_Keyboard_button *sym, MLV_Keyboard_modifier *mod, int *unicode)
Suspend l'exécution jusqu'à ce que l'utilisateur appuie sur une touche du clavier.