Enviado em 23/06/2017 - 21:37h
EDIT: Nem sei se o termo emulação está correto./*
* [dkbhit.c]
* Simula a função kbhit().
*
* [Autor]
* Daemonio (Marcos Paulo Ferreira)
* undefinido at gmail com
* https://daemoniolabs.wordpress.com
*
* Versão 1.0, by daemonio @ Thu Dec 27 20:40:22 BRST 2012
*/
#include <stdio.h>
#include <unistd.h>
#include <termios.h>
void init_attr(void) ;
void close_attr(void) ;
int kbhit(void) ;
struct termios old_attr, new_attr;
void init_attr(void) {
/* Obtém as configurações atuais. */
tcgetattr(0,&old_attr);
new_attr=old_attr;
/* Desliga modo canônico. */
new_attr.c_lflag &=~ICANON ;
/* Desliga ecoamento. */
new_attr.c_lflag &= ~ECHO;
new_attr.c_cc[VTIME]=0 ;
new_attr.c_cc[VMIN]=0 ;
}
/* Retorna configurações antigas. */
void close_attr(void) {
tcsetattr(STDIN_FILENO,TCSANOW,&old_attr);
}
int kbhit(void) {
int c ;
tcsetattr(STDIN_FILENO,TCSANOW,&new_attr);
c = getchar() ; /* retorna EOF se nada foi pressionado */
tcsetattr(STDIN_FILENO,TCSANOW,&old_attr);
return c ;
}
int main(void) {
int flag_ler_nome = 0;
char nome[20] ;
init_attr() ;
while(1) {
flag_ler_nome = kbhit() ;
if(flag_ler_nome != EOF) {
printf("Digite seu nome: ") ;
fgets(nome, sizeof nome, stdin) ;
}
printf("** Outros processamentos **\n") ;
}
close_attr() ;
return 0;
}
/* EOF */
#include <ncurses.h>
int main(void) {
initscr(); /* Start curses mode */
printw("Hello, World!"); /* Print Hello. World! */
refresh(); /* Print it on to the real screen */
getch(); /* Wait for user input */
endwin(); /* End curses mode */
return 0;
}
Desktop Linux ganha fôlego enquanto distros refinam experiência e segurança
Wayland em alta, IA em debate e novos ventos para distros e devices
Qt 6.10 e Python 3.14 puxam o ritmo do software livre nesta quarta
Atualizações de Apps, Desktop e Kernel agitam o ecossistema Linux nesta terça-feira
Como mudar o nome de dispositivos Bluetooth via linha de comando
Adicionando o repositório backports no Debian 13 Trixie
Não tenho som no meu Kali linux [RESOLVIDO] (3)
Primeiras impressões do Debian 13 (28)
Erro ao enviar notificação por e-mail (1)
Erro ao fazer remaster usando Penguin eggs (2)
Meu Amigo não consegue entrar em meu mundo, via tailscale, hamachi e z... (1)