Results 1 to 13 of 13

Thread: wide-character getch ()

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2002
    Posts
    195

    wide-character getch ()

    Is there a wide-character version of C's getch () function? I've tried getwchar () but it doesn't seem to work
    Using Visual Studio .NET 2005

  2. #2
    Hyperactive Member sw_is_great's Avatar
    Join Date
    Nov 2003
    Posts
    330
    what do u mean by wide-character version of getch()

    use scanf or gets for getting more than 1 character
    Regards

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Nov 2002
    Posts
    195
    I mean something like getch () which will return a WCHAR. I need to detect arrow key presses, and while I know how to interpret them (a leading NULL character) it seems bet to just use a WCHAR.
    So far, I'm using the following function, but I'd much prefer a standard function:
    Code:
    WCHAR CConsole::ReadKey ()
    {
    	if (!kbhit ()) return 0;
    
    	char lowCh = getch ();
    	if ((lowCh == -32) || (lowCh == 0)) // Arrow key or Function key
    		return ((getch () << 8) + lowCh);
    	else
    		return (WCHAR) lowCh;
    }
    Using Visual Studio .NET 2005

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    _getwch

    getch is a wrong name btw, it should be _getch.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Nov 2002
    Posts
    195
    there's nothing in the MSDN library about _getwch () and I'm unable to use it (Undeclared Identifier).
    Do I have to include a specific header? I've tried to find this myself, but everywhere say to use <conio.h> which doesn't work either.
    Last edited by Barguast; Dec 7th, 2003 at 05:22 PM.
    Using Visual Studio .NET 2005

  6. #6
    Hyperactive Member sw_is_great's Avatar
    Join Date
    Nov 2003
    Posts
    330
    why getch is a correct name and u need to include conio.h
    Regards

  7. #7
    Hyperactive Member sw_is_great's Avatar
    Join Date
    Nov 2003
    Posts
    330
    Barguast
    U can use keyboard interrupts to get the scan code for each key.U know that each key(including entre,F1......F12) have a unique scan code . u can use that..


    for this use int86 function..
    Regards

  8. #8
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    getch is a non-ANSI function. Therefore it should be prefixed with _. I believe MS does that, but it also provides the non-conforming name getch for compatibility with older apps, unless you enforce ANSI compatibility with the /Za compiler switch.

    _getch and _getwch are documented in my VS.Net 2003.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Nov 2002
    Posts
    195
    Originally posted by sw_is_great
    u need to include conio.h
    I'm still getting an 'undeclared identifier' error when i include this... I'm using MS Visual Studio 6.0 - could I have an outdated header file or something?
    Using Visual Studio .NET 2005

  10. #10
    Hyperactive Member sw_is_great's Avatar
    Join Date
    Nov 2003
    Posts
    330
    post ur code

    should be something like

    #include<stdio.h>
    #include<conio.h>
    main()
    {
    printf("\n Screen wait for me");
    getch();
    }
    Regards

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Nov 2002
    Posts
    195
    it's not _getch () I've got a problem with, it's _getwch ().
    Having tried the code you posted, but using _getwch () instead, I still get an undeclared identifier error for using _getwch ().
    Using Visual Studio .NET 2005

  12. #12
    Hyperactive Member sw_is_great's Avatar
    Join Date
    Nov 2003
    Posts
    330
    For trapping keyboard hits including enter key etc , use keyboard interrupts -

    they are fast
    reliable
    Regards

  13. #13
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    ...and don't work in real Win32 apps.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width