Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

A challenge to any who would call themselves a C++ God

I know this should be fairly easy (you see it everywhere), but how does one take input from the arrow keys? There is no documentation anywhere in any of the numerous books I have, and no one I've spoken to has a clue. There is no ASCII value for them, I've heard mention of reading the keyboard scan code, but not how this is accomplished. Does anyone have know of a standard library, or have one of their own they would be willing to share? I would most appreciate it.




Comments

  • I've only just learned this myself, and it is totally nonstandard (it won't necessarily work properly on another machine type).


    Most of the C console character reading routines (and this may also apply to the C++ cin.get()) return an int so that the value EOF for end-of-file can be differentiated from ascii value 255. However, nonstandard keys may be acquirable with a value greater than 255 (but hopefully still not equal to EOF).


    Look into getch, or getche... write a little routine that just dumps out the integer that they return, and then start punching a few keys.





  • When you use getch() with the arrow keys or the F keys, they actually send two ints. So you gotta do something like.


    int temp, temp2;

    temp = getch();

    if (temp == 0){ //check this....I think it's 0

    temp2 = getch();

    switch (temp2) {

    case 72: // check these out...the 4 arrow keys

    case 75: // are 70 something.

    case 78


    Mess around with it, but I had a problem with it and I know now that the arrow keys and F keys (F1-F12) send in two ints so you have to cascade 2 getch's.


    Hope this helps





  • : I know this should be fairly easy (you see it everywhere), but how does one take input from the arrow keys? There is no documentation anywhere in any of the numerous books I have, and no one I've spoken to has a clue. There is no ASCII value for them, I've heard mention of reading the keyboard scan code, but not how this is accomplished. Does anyone have know of a standard library, or have one of their own they would be willing to share? I would most appreciate it.

    I solved this problem by writing a library in

    16-bit x86 assembler. If you're compiling a DOS

    program, (NOT a 'Console-Mode' application!) and

    want to use this library, email me and I'll send

    you the .obj and .h files.

    Use the getextkey() function (in this library)

    to get the extended keys. To get the arrow keys,

    first check the low byte of the int returned for

    0xe0, and then check the high byte for:

    0x48 : up arrow

    0x50 : down arrow

    0x4D : right arrow

    0x4B : left arrow


    I think that every operating system has it's own

    unique ways of

    dealing with the "non-ASCII" keys - I don't think

    that there is a "portable" way of doing it...




    URL:http://www.angelfire.com/il/macroman

  • >>I know this should be fairly easy (you see it >>everywhere), but how does one take input from >>the arrow keys? There is no documentation >>anywhere


    Hi there,

    I dunno what you're talking about. You've said that there's no resource for getting a stream of characters from the basic input device - keyboard!

    But there's too many books all related to C/C++ programming out there that most of them cover this topic.

    Anyway, most of them uses this as the standard scheme:

    if(!getch())

    {

    ch = getch();

    switch(ch)

    {

    //whatever keys which have got 2 scan codes!

    //like arrow keys

    }

    }


    If your're gonna check those keys which have got only 1 scan code, then you can do that by this:

    ch = getch();

    without any additional source code!

    for example if the ch == 27 then the key is "ESC".


    But the non-standard scheme to do so, is playing with I/O ports! I've used them many times and they're so easy. Moreover, it uses just an assembly code... I've used it in my TSR programs, but unfortunately I can't share it with ya!


    Hope this little (?) description helps ya!

    Cheers,

    M.Mousavi




    URL:http://www.tabesh.com

Sign In or Register to comment.