Thread: Check key state once per frame

  1. #16
    Captain - Lover of the C
    Join Date
    May 2005
    Posts
    341
    I gave you two great macros that you can put up at the top of you code. Then use it like I used it in the example I gave. At least try that and post your code.
    Don't quote me on that... ...seriously

  2. #17
    Math wizard
    Join Date
    Dec 2006
    Location
    USA
    Posts
    582
    Okay, it's now working as expected. I found bug in my program along the way, but it's not related to the keyboard stuff. What is the difference between my original and that of your macros?

  3. #18
    Captain - Lover of the C
    Join Date
    May 2005
    Posts
    341
    You're check
    Code:
    KeyOn = -32767
    -32767 = 0x8001
    0x8001 will work when the key has been press since the last time you call GetAsyncKeyState.
    if the key was down last time you check and is still down then GetAsyncKeyState will return 0x8000 and your check should fail. The macros I provided would not fail.
    Don't quote me on that... ...seriously

  4. #19
    Math wizard
    Join Date
    Dec 2006
    Location
    USA
    Posts
    582
    Ah, that explains it. I got that -32767 number from an experiment. In the manual, I saw "most significant bit", so I expected either 32768 (if unsigned) or -32768 (if signed), but I couldn't explain why I got -32767. I created a temporary variable then after 4 seconds (240 frames), I got it to get that value and every time I did the test, that's all I got and thus I went with that only.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 11-23-2007, 01:48 PM
  2. Check state of buttons
    By Sober in forum Windows Programming
    Replies: 2
    Last Post: 05-03-2007, 02:23 PM
  3. input/switch statement issues
    By peanut in forum C Programming
    Replies: 5
    Last Post: 10-27-2006, 02:58 PM
  4. About aes
    By gumit in forum C Programming
    Replies: 13
    Last Post: 10-24-2006, 03:42 PM
  5. BST/Red and Black Tree
    By ghettoman in forum C++ Programming
    Replies: 0
    Last Post: 10-24-2001, 10:45 PM