Não conseguimos carregar os anúncios.Se usa bloqueador, considere liberar o Viva o Linux para nos patrocinar.
Pressionar tecla e não precisar pressionar ENTER
Essa função eu peguei do código do cdplayer de console workbone. O que ela faz é configurar o terminal onde o programa está sendo executado para fazer com que teclas pressionadas sejam lidas pela função getc sem a necessidade de se pressionar ENTER. Para ativar essa funcionalidade basta usar rl_ttyset(0), e para desativar rl_ttyset(1).
void
rl_ttyset (int reset)
{
static struct termios old; // Armazena as configuracoes antigas
struct termios new; // Recebe as novas configuracoes
if (reset == 0)
{
(void) tcgetattr (0, &old);
new = old; // Copia as configuracoes antigas
new.c_lflag &= ~(ECHO | ICANON);
new.c_iflag &= ~(ISTRIP | INPCK);
void) tcsetattr (0, TCSANOW, &new); // Habilita as novas configuracoes
}
else
(void) tcsetattr (0, TCSANOW, &old); // Restaura as configuracoes antigas
}
#1Comentário enviado por duda_augusto em 29/11/2004 - 20:14h
Meio apagada, mas é interessante a dica.
Diferente vamos dizer.
#2Comentário enviado por hunz em 04/12/2004 - 20:29h
Olha o erro que da aqui:
bash-2.05b$ gcc main.c -o teste
main.c: In function `rl_ttyset':
main.c:31: error: storage size of `old' isn't known
main.c:32: error: storage size of `new' isn't known
main.c:38: error: `ECHO' undeclared (first use in this function)
main.c:38: error: (Each undeclared identifier is reported only once
main.c:38: error: for each function it appears in.)
main.c:38: error: `ICANON' undeclared (first use in this function)
main.c:39: error: `ISTRIP' undeclared (first use in this function)
main.c:39: error: `INPCK' undeclared (first use in this function)
main.c:40: error: `TCSANOW' undeclared (first use in this function)
main.c:31: error: storage size of `old' isn't known
main.c: In function `main':
main.c:270: warning: passing arg 1 of `_IO_getc' makes pointer from integer without a cast
Não funcionou isso ai não :(
Se souber como arrumar: manda um e-mail pra mim tn_negri@hotmail.com
Abraços,
Fiquem com Deus.
#3Comentário enviado por removido em 06/12/2004 - 07:42h
É fácil, apenas inclua os arquivos termios.h e unistd.h
#include <termios.h>
#include <unistd.h>
#4Comentário enviado por jochan em 14/12/2005 - 14:48h
Muito legal, vai me ajudar bastente no meu projeto de C++ ... =)
#5Comentário enviado por LittleLinuxMEN em 10/06/2007 - 13:29h
maravilha.... já consigo fazer um HelloWorld a ler a tecla sem o ENTER.
Diferente vamos dizer.