Documentation de la bibliothèque MLV-2.0.2

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/>.
*/