Documentation de la bibliothèque MLV-3.1.0

medium/10_mouse_or_keyboard_access.c

Ce programme montre comment il est possible de connaître l'état courant d'une touche d'un clavier ou de la position courante de la souris.

#include <MLV/MLV_all.h>
#include <stdio.h>
//
// 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, height=480;
//
// On créé et affiche la fenêtre
//
MLV_create_window( "medium - 4 events", "4 events", width, height );
while( 1 ){
//
// On commence par nettoyer l'écran
//
//
// On récupère puis affiche l'état de la touche a
//
if( MLV_get_keyboard_state( MLV_KEYBOARD_k ) == MLV_PRESSED ){
0, 20, "L'utilisateur est en train d'appuyer sur la touche k",
);
}else{
0, 20,
"L'utilisateur n'est pas en train d'appuyer sur la touche k",
);
}
//
// On récupère puis affiche la position de la souris
//
int x,y;
0, 40,
"Position de la souris : (%d, %d)",
x, y
);
//
// On récupère puis affiche l'état du bouton gauche de la souris.
//
0, 60,
"L'utilisateur est en train de cliquer sur le bouton gauche de la souris.",
);
}else{
0, 60,
"L'utilisateur n'est pas en train de cliquer sur le bouton gauche de la souris.",
);
}
//
// On met à jour l'affichage.
//
}
//
// On libère la fenêtre
//
return 0;
}
/*
* This file is part of the MLV Library.
*
* Copyright (C) 2010,2011,2012,2013 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_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_BUTTON_LEFT
@ MLV_BUTTON_LEFT
Definition: MLV_mouse.h:52
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_draw_text
void MLV_draw_text(int x, int y, const char *text, MLV_Color color,...)
Imprime un texte donné à une position et une couleur données.
MLV_get_keyboard_state
MLV_Button_state MLV_get_keyboard_state(MLV_Keyboard_button keyboard_code)
Renvoie l'état (préssé ou relaché) d'une touche donnée d'un clavier.
MLV_COLOR_GREEN
#define MLV_COLOR_GREEN
Definition: MLV_color.h:931
MLV_get_mouse_position
void MLV_get_mouse_position(int *x, int *y)
Renvoie la position courante de la souris.
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_PRESSED
@ MLV_PRESSED
Definition: MLV_device_with_buttons.h:44
MLV_COLOR_BLACK
#define MLV_COLOR_BLACK
Definition: MLV_color.h:379
MLV_get_mouse_button_state
MLV_Button_state MLV_get_mouse_button_state(MLV_Mouse_button mouse_button)
Renvoie l'état (préssé ou relaché) d'un bouton de la souris.