Results 1 to 7 of 7

Thread: Virtual Keys

  1. #1

    Thread Starter
    Frenzied Member CyberCarsten's Avatar
    Join Date
    Sep 1999
    Location
    Aalborg Ø, Denmark
    Posts
    1,544

    Virtual Keys

    I'm trying to trap the 'W' key with the following code, but it doesn't work:

    Code:
    if (KEY_DOWN(VK_W))
    	// Move player two up
    Code:
    if (KEY_DOWN(57))
    	// Move player two up
    Neither works...
    razor
    Software Engineer Student, Aalborg University, Denmark
    http://www.cs.auc.dk

    My email at AUC: will get a new email soon
    My website: http://www.razorsoftware.net


    Windows XP Pro/ Gentoo Linux (Laptop)
    Windows XP Pro (Home PC)

  2. #2
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    Try using GetAsyncKeyState instead of KEY_DOWN.
    Baaaaaaaaah

  3. #3
    Fanatic Member MoMad's Avatar
    Join Date
    Oct 2000
    Location
    Seattle, WA
    Posts
    625
    What is KEY_DOWN?? Where did u get that? Is it a MACRO of some sort? Try what abdul said or just do a

    #define KEY_DOWN(x) GetAsyncKeyState(x)
    :MoMad:
    Nice Sig!

    http://go.to/momad/ Status: Not Ready

  4. #4
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    I've had troubles with it

  5. #5
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    GetAsyncKeyState will return 0 if it fails so you should check it like this....
    PHP Code:
    if(GeAsyncKeyState(0x57) != 0)
    {
    //Key was pressed

    Remember the code for the "W" key is in hexadecimal (0x57), not just 57.
    Baaaaaaaaah

  6. #6

    Thread Starter
    Frenzied Member CyberCarsten's Avatar
    Join Date
    Sep 1999
    Location
    Aalborg Ø, Denmark
    Posts
    1,544
    oohhh! now I get it! thx!
    razor
    Software Engineer Student, Aalborg University, Denmark
    http://www.cs.auc.dk

    My email at AUC: will get a new email soon
    My website: http://www.razorsoftware.net


    Windows XP Pro/ Gentoo Linux (Laptop)
    Windows XP Pro (Home PC)

  7. #7
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    The return value of GetAsyncKeyState should only be tested for the highest bit set:
    Code:
    inline bool KEY_DOWN(int vk) {
      return (GetAsyncKeyState(vk) & 0x80) != 0;
    }
    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