Thread: get the key stroke in Win32 Console Project

  1. #1
    Registered User
    Join Date
    Mar 2008
    Posts
    6

    get the key stroke in Win32 Console Project

    hi,
    i am doing a simple win32 console program that whenever press a key on the keyboard the program will get the char pressed by the user. I have tried cin, and getchar, but both of them will need to press enter to continue the program, it there anyway to trigger the function whenever a key is pressed??

    Cheers

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Have a look in the FAQ - or search the Forum. This question comes up in one form or another every couple of weeks or so.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    2,158
    there's getch() too. Or, you could call GetAsyncKeyState to check if a button is down, right after kbhit is freed.
    ... are you at all related to maxorator?

  4. #4
    Registered User
    Join Date
    Nov 2002
    Posts
    319
    just turn it in to a win32 project and use WM_CHAR in the switch msg loop ,
    and to get a console up use AllocateConsole , WrtieConsole

  5. #5
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by Anddos View Post
    just turn it in to a win32 project and use WM_CHAR in the switch msg loop ,
    and to get a console up use AllocateConsole , WrtieConsole
    And when you go to work, I suppose you climb out the window, up on the roof and down the other side, because that's better than going out the front door?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  6. #6
    Just a Human Anuradh_a's Avatar
    Join Date
    Jan 2008
    Posts
    50
    hey guys
    for GetAsyncKeyState() can't we use GetKeyState() ?????
    thanks

  7. #7
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    I expect there will be little difference, but MSDN says this about GetKeyState:
    The key status returned from this function changes as a thread reads key messages from its message queue. The status does not reflect the interrupt-level state associated with the hardware. Use the GetAsyncKeyState function to retrieve that information.
    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. icon in win32 console application
    By osal in forum Windows Programming
    Replies: 3
    Last Post: 06-30-2004, 02:13 PM
  2. Text based frames in win32 console
    By Ragger in forum C Programming
    Replies: 6
    Last Post: 06-19-2004, 08:09 AM
  3. Project Builder console app
    By Luigi in forum C++ Programming
    Replies: 0
    Last Post: 12-28-2002, 07:57 PM
  4. Registery with api?
    By ismael86 in forum Windows Programming
    Replies: 1
    Last Post: 05-14-2002, 10:28 AM
  5. BST/Red and Black Tree
    By ghettoman in forum C++ Programming
    Replies: 0
    Last Post: 10-24-2001, 10:45 PM