Detection clavier en C ANSI
Fermé
castor
Messages postés
17747
Date d'inscription
mardi 3 juillet 2001
Statut
Modérateur
Dernière intervention
11 mars 2015
-
24 avril 2002 à 17:34
castor Messages postés 17747 Date d'inscription mardi 3 juillet 2001 Statut Modérateur Dernière intervention 11 mars 2015 - 29 avril 2002 à 09:10
castor Messages postés 17747 Date d'inscription mardi 3 juillet 2001 Statut Modérateur Dernière intervention 11 mars 2015 - 29 avril 2002 à 09:10
A voir également:
- Detection clavier en C ANSI
- Changer clavier qwerty en azerty - Guide
- Clavier+ - Télécharger - Personnalisation
- Cliquez sur ce lien. en n'utilisant que le clavier, quel mot obtenez-vous ? ✓ - Forum souris / Touchpad
- C cédille clavier - Forum Word
- Mon clavier n'écrit plus ✓ - Forum Clavier
4 réponses
jisisv
Messages postés
3645
Date d'inscription
dimanche 18 mars 2001
Statut
Modérateur
Dernière intervention
15 janvier 2017
947
24 avril 2002 à 17:51
24 avril 2002 à 17:51
Il faut peut-être voir du côté de
man 3 termios
Allways close to Open Source...
Johan Daine
man 3 termios
Allways close to Open Source...
Johan Daine
castor
Messages postés
17747
Date d'inscription
mardi 3 juillet 2001
Statut
Modérateur
Dernière intervention
11 mars 2015
136
25 avril 2002 à 09:29
25 avril 2002 à 09:29
NOM
termios, tcgetattr, tcsetattr, tcsendbreak, tcdrain,
tcflush, tcflow, cfmakeraw, cfgetospeed, cfgetispeed,
cfsetispeed, cfsetospeed, tcgetpgrp, tcsetpgrp - Consulter
ou indiquer les attributs de terminaux, le contrôle de
ligne, la vitesse de transmission et le GID du processus
en avant-plan sur un terminal.
c bien ce que je pensais, c par rapport au terminal... mais bon je copntinue l'exploration qd mm ds ce man...
.O
(_)__... Castor
termios, tcgetattr, tcsetattr, tcsendbreak, tcdrain,
tcflush, tcflow, cfmakeraw, cfgetospeed, cfgetispeed,
cfsetispeed, cfsetospeed, tcgetpgrp, tcsetpgrp - Consulter
ou indiquer les attributs de terminaux, le contrôle de
ligne, la vitesse de transmission et le GID du processus
en avant-plan sur un terminal.
c bien ce que je pensais, c par rapport au terminal... mais bon je copntinue l'exploration qd mm ds ce man...
.O
(_)__... Castor
castor
Messages postés
17747
Date d'inscription
mardi 3 juillet 2001
Statut
Modérateur
Dernière intervention
11 mars 2015
136
25 avril 2002 à 09:31
25 avril 2002 à 09:31
DESCRIPTION
Les fonctions termios établissent une interface générale
sous forme de terminal, permettant de contrôler les ports
de communication asynchrone.
c bien ca... juste les ports com.....
mais ct une bonne idee, merci jisisv
.O
(_)__... Castor
Les fonctions termios établissent une interface générale
sous forme de terminal, permettant de contrôler les ports
de communication asynchrone.
c bien ca... juste les ports com.....
mais ct une bonne idee, merci jisisv
.O
(_)__... Castor
jisisv
Messages postés
3645
Date d'inscription
dimanche 18 mars 2001
Statut
Modérateur
Dernière intervention
15 janvier 2017
947
25 avril 2002 à 10:34
25 avril 2002 à 10:34
Voici un code extrait des sources du livre "Beginning Linux Programming" de Neil Matthews chez Wrox
(voi le chargement sur http://www.wrox.com )
#include <stdio.h>
#include <termios.h>
#include <term.h>
#include <curses.h>
#include <unistd.h>
static struct termios initial_settings, new_settings;
static int peek_character = -1;
void init_keyboard();
void close_keyboard();
int kbhit();
int readch();
int main()
{
int ch = 0;
init_keyboard();
while(ch != 'q') {
printf("looping\n");
sleep(1);
if(kbhit()) {
ch = readch();
printf("you hit %c\n",ch);
}
}
close_keyboard();
exit(0);
}
void init_keyboard()
{
tcgetattr(0,&initial_settings);
new_settings = initial_settings;
new_settings.c_lflag &= ~ICANON;
new_settings.c_lflag &= ~ECHO;
new_settings.c_lflag &= ~ISIG;
new_settings.c_cc[VMIN] = 1;
new_settings.c_cc[VTIME] = 0;
tcsetattr(0, TCSANOW, &new_settings);
}
void close_keyboard()
{
tcsetattr(0, TCSANOW, &initial_settings);
}
int kbhit()
{
char ch;
int nread;
if(peek_character != -1)
return 1;
new_settings.c_cc[VMIN]=0;
tcsetattr(0, TCSANOW, &new_settings);
nread = read(0,&ch,1);
new_settings.c_cc[VMIN]=1;
tcsetattr(0, TCSANOW, &new_settings);
if(nread == 1) {
peek_character = ch;
return 1;
}
return 0;
}
int readch()
{
char ch;
if(peek_character != -1) {
ch = peek_character;
peek_character = -1;
return ch;
}
read(0,&ch,1);
return ch;
}
Allways close to Open Source...
Johan Daine
(voi le chargement sur http://www.wrox.com )
#include <stdio.h>
#include <termios.h>
#include <term.h>
#include <curses.h>
#include <unistd.h>
static struct termios initial_settings, new_settings;
static int peek_character = -1;
void init_keyboard();
void close_keyboard();
int kbhit();
int readch();
int main()
{
int ch = 0;
init_keyboard();
while(ch != 'q') {
printf("looping\n");
sleep(1);
if(kbhit()) {
ch = readch();
printf("you hit %c\n",ch);
}
}
close_keyboard();
exit(0);
}
void init_keyboard()
{
tcgetattr(0,&initial_settings);
new_settings = initial_settings;
new_settings.c_lflag &= ~ICANON;
new_settings.c_lflag &= ~ECHO;
new_settings.c_lflag &= ~ISIG;
new_settings.c_cc[VMIN] = 1;
new_settings.c_cc[VTIME] = 0;
tcsetattr(0, TCSANOW, &new_settings);
}
void close_keyboard()
{
tcsetattr(0, TCSANOW, &initial_settings);
}
int kbhit()
{
char ch;
int nread;
if(peek_character != -1)
return 1;
new_settings.c_cc[VMIN]=0;
tcsetattr(0, TCSANOW, &new_settings);
nread = read(0,&ch,1);
new_settings.c_cc[VMIN]=1;
tcsetattr(0, TCSANOW, &new_settings);
if(nread == 1) {
peek_character = ch;
return 1;
}
return 0;
}
int readch()
{
char ch;
if(peek_character != -1) {
ch = peek_character;
peek_character = -1;
return ch;
}
read(0,&ch,1);
return ch;
}
Allways close to Open Source...
Johan Daine
castor
Messages postés
17747
Date d'inscription
mardi 3 juillet 2001
Statut
Modérateur
Dernière intervention
11 mars 2015
136
29 avril 2002 à 09:04
29 avril 2002 à 09:04
Je viens de voir que ma reponse n'est aps apparue dans le forum...
je disais donc: "merci jisiv, ca marche nikel t le meileur" :-D
.O
(_)__... Castor
je disais donc: "merci jisiv, ca marche nikel t le meileur" :-D
.O
(_)__... Castor
grosquik_
Messages postés
33
Date d'inscription
jeudi 18 avril 2002
Statut
Membre
Dernière intervention
26 avril 2002
25 avril 2002 à 12:48
25 avril 2002 à 12:48
essaye keypress()
il devrait de retourner 1 dés qu'une touche est dans le beffer du clavier
(tu le relis avec getch() )
il devrait de retourner 1 dés qu'une touche est dans le beffer du clavier
(tu le relis avec getch() )
castor
Messages postés
17747
Date d'inscription
mardi 3 juillet 2001
Statut
Modérateur
Dernière intervention
11 mars 2015
136
29 avril 2002 à 09:10
29 avril 2002 à 09:10
salut grosquik
merci du tuyau, mais g pas trouve la lib qui contient "keypress", et un "man keypress" m'envoie balader ;)
tu as la lib a inclure stp?
.O
(_)__... Castor
merci du tuyau, mais g pas trouve la lib qui contient "keypress", et un "man keypress" m'envoie balader ;)
tu as la lib a inclure stp?
.O
(_)__... Castor
24 avril 2002 à 17:56
mais je vais y jeter un coup d'oeil, merci jisisv
.O
(_)__... Castor