Alright how do you flag down individual keys on a keyboard, getchar() just don't cut it, for 2 reasons:
1. I don't like the post enter delimma (Yes i've read the Eskimo guy's note)
2. It's only for ASCII and that doesn't cover ALL keys

So really my question is, what function can I use to get the SPECIFIC character that a user presses

I don't care if it returns a number or character, I just want a function, and probably not getchar(), to return the specific value of whatever key was pressed, and even diffrenciate between regular 1 and num pad 1, as well as include all other "standard" 102 key keyboard keys like "del", "sys rq" or "arrow up".

Thanks so much for taking the time to read this and for the time of your reply, it really means alot.

01-05-2004

quzah

You simply don't understand how key presses work. Some keys (the arrow keys, the F keys) are counted as more than one keypress. Not just a single keystroke. Basicly what you do is read a keystroke, test the first value. If it's the escaped sequence, then you read the second value to see what escaped key they've pressed.

For example, and 'a' is just an 'a'. Others are a pair of keys. The first is a zero, not a '0', but the actual value zero, followed by another keystroke, which is then translated to the other keystroke.

Anyway, there is no ANSI standard way to read a keystroke. It will depend on your OS and compiler.

Quzah.

01-05-2004

linuxdude

also don't declare variables in the middle of your program. That is c99 standard and c++ not c

01-05-2004

VirtualAce

You guys and your standards. Give the guy a break.

Trapping keys via the built-in C functions are going to be both slow and cumbersome. In Windows there are several functions that test for keys - all of em. In DirectX, you are given full control of the keyboard....just enough to make you dangerous anyways.

01-05-2004

quzah

Quote:

Originally posted by Bubba You guys and your standards. Give the guy a break.

Why? They didn't specify anything about the envoirnment they were writing for. Thus, it's only logical to provide them the best answer possible for the given parameters of the question. See below.

Quote:

Originally posted by Bubba Trapping keys via the built-in C functions are going to be both slow and cumbersome. In Windows there are several functions that test for keys - all of em. In DirectX, you are given full control of the keyboard....just enough to make you dangerous anyways.

Your answers are absolutely worthless if he isn't working with Windows. That's the reason for mentioning standards.

Quzah.

01-05-2004

VirtualAce

Quote:

also don't declare variables in the middle of your program. That is c99 standard and c++ not c

Hmm...unless I can't read I can't see anything in this about platform or OS. That was not the reason for him posting about standards and such.

01-05-2004

Axpen

Update

Sorry about not knowing the specifics on keyboard input, I literally have no clue about that (although not because of lack of effort). So I guess I should just ask is there a site any of you all know that tells about how keyboard input works or anything (because i've looked up and down on google and this site and there isn't anything) like that. All I really want is the knowledge of how to tell what key or keys a user is pressing, like Ctrl+S for save or again how to tell what combination of key codes makes up a left shift or a right shift.

Thanks alot for all the help thus far, I really appriciate it.

01-05-2004

linuxdude

didn't mean to start a war. Let's get back to the question. Is there a standard way? I don't know how to get two keys from a user at the same time. I think each operating system would have its own 2byte integer for that keypress. I am just guessing I have no clue. Does anyone here know?

Assuming you're own some flavor of Windows, unless you have a PAUSE script.

gg

01-06-2004

WaltP

Re: Update

Quote:

Originally posted by Axpen All I really want is the knowledge of how to tell what key or keys a user is pressing, like Ctrl+S for save or again how to tell what combination of key codes makes up a left shift or a right shift.

Thanks alot for all the help thus far, I really appriciate it.

6 of the 8 posts that responded to you mentioned in some way that your request is:1) compiler specific -- this means we cannot give you an answer because you have yet to tell us what compiler is being used2) system specific -- this means we cannot give you an answer because you have yet to tell us what operating system is being used

Did you somehow miss that? Even from all these clues:
It will depend on your OS and compiler.
In Windows...
They didn't specify anything about the envoirnment they were writing for...
I can't see anything in this about platform or OS.
I think each operating system would have its own ...
Assuming you're own some flavor of Windows

I may have found a solution but Dev-C++ doesn't have much documentation on the topic, the solution is using inline assembly and using DOS interrupt 16h to catch the scan code as well as the ASCII code but I can't figure out how to get inline assembly to work in Dev-C++.

That was basically the same as the code from the author of C for Dummies Code and Concept Here but that nor

Code:

__asm
{
mov ah,10h
int 16h
mov key,ax
}

that works, any ideas on Dev-C++ inline assembly would be GREATLY appriciated, thanks.

01-06-2004

caroundw5h

Quote:

Originally posted by linuxdude also don't declare variables in the middle of your program. That is c99 standard and c++ not c

To be honest, i find its sometimes more productive and reader friendly. There is no way you know what you will need all the time before you code.

Besides if C++ was meant to be a more porductive way to code C, then that means it is good form, and practice. IMHO.

In anycase. Its more an asthethic style.

I'm also glad to see your not copying the authours code verbatim. As you can see, even main doesn't return an integer. I've been warnded to stay away from books like that. :D

01-06-2004

Codeplug

>> Alright i'm using Dev-C++ 4.9.8.0 (Just downloaded two nights ago) and am using Windows XP home.
If you want to write a Windows application, then use the links in my previous post.
If you want to write a DOS application that runs in the Virtual DOS Machine (VDM) in WindowsXP, then you need to download another compiler: DJGPP.

The code you're trying to use will only work in DOS.

gg

01-06-2004

chrismiceli

Quote:

Originally posted by caroundw5h
To be honest, i find its sometimes more productive and reader friendly. There is no way you know what you will need all the time before you code.

Besides if C++ was meant to be a more porductive way to code C, then that means it is good form, and practice. IMHO.

In anycase. Its more an asthethic style.

Well we program in C, so why practice c++ when writing programs in C?

01-08-2004

Axpen

Problem solved, but with confusion

I got and working thanks to the link to here, however, although it solved my problem there was something there I didn't understand, the 0xE0, what significance does that play? I understand 256's role, since extended characters that aren't ASCII have null ASCII code you need more than the first byte of scan code. Even after reading msdn's reference and goldenrock's ASCII key code link I still don't understand the 0xE0 (and yes i'm aware that's 224 in decimal) I still don't understand it.