Write a program to store every character typed at the keyboard into a file. The procedure should come to an end as soon as the ‘Esc’ key ispressed.
#include<iostream.h>
#include<conio.h>
using namespace std;
int main () {
while (true) {
if(_kbhit()){
int ch = 0 | _getch();
if(ch == 0xe0 && _kbhit()){ // extended character (0xe0, xxx)
ch = (ch<<8) | _getch(); // get extended xharaxter info
}
switch(ch){
case 0x1b:
cout << "ESC pressed" << endl;
break;
case 0xe048:
cout << "Up pressed" << endl;
break;
case 0xe050:
cout << "Down pressed" << endl;
break;
case 0xe04b:
cout << "Left pressed" << endl;
break;
case 0xe04d:
cout << "Right pressed" << endl;
break;
default:
cout << "Some other key pressed " << hex
<< (int)(unsigned char)ch << " '"
<< (char)ch << "'" << endl;
break;
}
cout << endl;
}
}
return 0;
}
#include<iostream.h>
#include<conio.h>
using namespace std;
int main () {
while (true) {
if(_kbhit()){
int ch = 0 | _getch();
if(ch == 0xe0 && _kbhit()){ // extended character (0xe0, xxx)
ch = (ch<<8) | _getch(); // get extended xharaxter info
}
switch(ch){
case 0x1b:
cout << "ESC pressed" << endl;
break;
case 0xe048:
cout << "Up pressed" << endl;
break;
case 0xe050:
cout << "Down pressed" << endl;
break;
case 0xe04b:
cout << "Left pressed" << endl;
break;
case 0xe04d:
cout << "Right pressed" << endl;
break;
default:
cout << "Some other key pressed " << hex
<< (int)(unsigned char)ch << " '"
<< (char)ch << "'" << endl;
break;
}
cout << endl;
}
}
return 0;
}
No comments:
Post a Comment
Note: only a member of this blog may post a comment.