Results 1 to 4 of 4

Thread: GetKeyboardState()

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800

    GetKeyboardState()

    can someone give me an example? mine never works?

    i know i know you're all sick of me asking...but its due friday and I haven't gotten it to work yet
    Last edited by SteveCRM; Oct 22nd, 2002 at 04:18 PM.

  2. #2
    Hyperactive Member
    Join Date
    Sep 2001
    Posts
    396
    I think you should forget about GetKeyboardState(). I couldn't get it working in either MFC or win32. It always fail and give me back a null pointer.

    I would suggest you to use back GetAsyncKeyState().

    I have attached a working code which uses GetAsyncKeyState(). This program can detect up to any 3 keys simultaneously.(VK_SPACE is to quit). Modify it to your needs or up to more than 3 keys (don't worry;very easy to do).

    But I would suggest you use it this way. Eg, you want to detect 4 keys, A, B, C, D.

    PHP Code:
    if(GetAsyncKeyState(0x41) & 0x8000)//==A key pressed
    {
    //Do what you want here
    }
    if(
    GetAsyncKeyState(0x42) & 0x8000)//==B key pressed
    {
    //Do what you want here
    }
    if(
    GetAsyncKeyState(0x43) & 0x8000)//==C key pressed
    {
    //Do what you want here
    }
    if(
    GetAsyncKeyState(0x44) & 0x8000)//==D key pressed
    {
    //Do what you want here

    To use my code, use appwizard to generate a Win32 hello world app. Name the project SteveWin32. then copy my cpp file there.

    Note: I don't know if you can just compile it without doing all these.
    Attached Files Attached Files

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    thanks so much for answering...but I have to use a console application...and in the console I've never gotten GetAsyncKeyState() to work for the keyboard (works for the mouse)...

    thats why I was trying GetKeyboardState().

    is there a way to make it work in a win32 console?

    thanks

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    I think not, and under normal circumstances (that is when you want to write an app that does something useful, not a school project) you don't need it.
    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