Originariamente inviato da XWolverineX
Bhe si alla fine quello è un messaggio gestito dal WndProc però alla fine è come un evento.
Però questi Mesg posso usarli solo con le finestre di windows. Come intercetto gli eventi con programmi da Console? tipo quando premi un pulsante....
Io, di solito, faccio così:
codice:
#include <stdio.h>
#include <conio.h>
int main( void )
{
char hkey, key;
while (key != 27) // Esci se premi il tasto ESC
{
if( kbhit() ) // Rileva la pressione di un tasto
{
hkey = 0;
key = getch();
if(key == 0)
{
hkey = -1; //
key = getch();
}
if( hkey == -1)
{
printf("hkey = H%3i key = %3i ext \r", hkey, key);
switch(key)
{
case 77: // Codice tasto freccia dx
//
break;
case 75: // Codice tasto freccia sx
//
break;
case 80: // Codice tasto freccia su
//
break;
case 72: // Codice tasto freccia giu'
//
break;
}
}
else
{
printf("hkey = H%3i key = %3i (%c) \r", hkey, key, key);
switch(key)
{
case 13: // Codice tasto INVIO
//
break;
case 32: // Barra spazio
//
break;
}
}
}
}
return 0;
}
Intendevi una cosa del genere ?