Computing.Net > Forums > Programming > C++ keyboard interfacing...

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

C++ keyboard interfacing...

Reply to Message Icon

Name: David Gurba
Date: January 18, 2002 at 17:52:46 Pacific
Comment:

hello, I am writing a program that waits for a user to press a key on the keyboard, and then verify the scancode (...or Ascii code) generated by the keystroke.

So an example run may be:
Please press ESC key: (press key)
Esc key was pressed and is OK.
End program.

I have tried capture keyboard data in Ada95, and believe I will run into the same problem in C++ in that I will not be able to get the control characters (Tab, Shift, Control...ect). How do I interface into the OS's (windows or Linux...Linux prefered..:) ) "virtual keyboard" buffer to obtain the keys pressed during the run of my program? Any help...thnx



Sponsored Link
Ads by Google

Response Number 1
Name: sambasivarao
Date: January 20, 2002 at 18:55:12 Pacific
Reply:

hi
please reply for this


0

Response Number 2
Name: Lee Garner
Date: January 23, 2002 at 19:30:26 Pacific
Reply:

#include
#include

void main(void)
{
while (1) {
if (kbhit()) {
key = getch();
if (key == 0) // get extended keycode
key = getch();
printf("%d %x\n", key, key);
if (key == 27) return;
}
}
}

Works under DOS (& Windows) and Netware, linux might be different. Prints the decimal and hex values for keystrokes. Also check http://linux.nf/kbhit.html


0

Response Number 3
Name: radon
Date: January 26, 2002 at 15:22:56 Pacific
Reply:

Those two include statements probably should have been:

#include [iostream.h]
#include [conio.h]

replace the [] with greater-than and less-than signs.


0

Response Number 4
Name: Venkat Raghavulu A.R
Date: January 27, 2002 at 07:35:34 Pacific
Reply:

Hi,
Its long i used this command, i remember it remotely. If u r using Borland C++(Turbo C++), then there is one function KEYBRDREAD(), it returns a unique number ( i guess it is long) number for every key pressed, even for ESC, space, F1, F2 etc. Do some R&D for it.Check the help, IT IS THERE IN IT. Just patiently check for the function, i do not remember the exact name of the function. But belive me it is very perfect. If u r using VC++, then let me know i will help u out.
Plz let me know when u have found out it.
A word of caution it is a blocking call i.e, it does not come out until a key is pressed.
Venkat Raghavulu.


0

Response Number 5
Name: Dang Ngoc Khoa
Date: February 26, 2002 at 18:22:54 Pacific
Reply:

hi
please reply for this
thanks a lot


0

Related Posts

See More



Response Number 6
Name: Michiel
Date: May 10, 2002 at 04:32:12 Pacific
Reply:

This is a program for wich ASCII code belongs to wich key. The program was origanally in Dutch but i changed the interface to English.
When you strike a key like F1 you get a code like this: 0.59 This is not the code you must use when you write your program. You first have to detect the first code '0'. Immediatly after that you "catch" the second code '59' and then it knows you pressed F1. If you need an example with comment of this you can e-mail me. BTW there is an example in this program.

#include
#include
#include

int Menu(char keuze);
void ToetsChar();
void AlleChars();

void main()
{
char K;
char keuze;

do {
K = Menu(keuze);

switch (K)
{
case '1' : ToetsChar(); break;
case '2' : AlleChars(); break;
case '3' : break;
}
} while (K!='3');
}

int Menu(char keuze)
{
clrscr();
cout > keuze;

return keuze;
}

void ToetsChar()
{
clrscr();
int toets,tel;
char toets2;

cout to return to the menu\n\n";

for (; toets!=27;)
{
toets=getch();
toets2=toets;
if (toets == 0)
{
cout \n";
getch();

for (karak=27,tel=1; karak<=255; karak++,tel++)
{

symb=karak;
cout << karak << " = "<< symb << endl;
delay(10);

if (tel == Eind_Scherm)
{
cout << "Press a key";
getch();
clrscr();
tel=1;
Eind_Scherm = 25;
}
}
cout << "Press a key to return to the menu";
getch();
}


0

Response Number 7
Name: Art Geigel
Date: May 23, 2002 at 06:22:19 Pacific
Reply:

Is there a way to constantly track keys pressed, even when the C++ program is not the active form? I mean that the program is running but is in the background. So can a person be using Word and there still be a way to extract the keys they pressed from the buffer? Please email me or post code. Thanks a bunch.


0

Sponsored Link
Ads by Google
Reply to Message Icon

VB Hyperlink win32 console programming



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: C++ keyboard interfacing...

keyboard interfacing www.computing.net/answers/programming/keyboard-interfacing/9211.html

C++ Graphical Interface www.computing.net/answers/programming/c-graphical-interface/9381.html

C++: Keyboard Button Capturing www.computing.net/answers/programming/c-keyboard-button-capturing/1691.html