Length of keypress question

This is a discussion on Length of keypress question within the Windows Programming forums, part of the Platform Specific Boards category; Awesome board you've got here. Everyone is incredibly helpful and informative. Thanks in advance for any help with my problem. ...

  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    4

    Length of keypress question

    Awesome board you've got here. Everyone is incredibly helpful and informative. Thanks in advance for any help with my problem.

    I've Google'd this (is how I ended up here) and read your FAQ and done a search on this board and have found some interesting possibilities, but didn't find a definitive answer.

    I'm using Dev-cpp and WinXP.

    I'd like to be able to tell when the user has held down the key for double or triple the time of a normal keypress. For instance, tapping 'T' causes the gun to fire single shots, but holding 'T' down will cause a more powerful shot to occur after 1 second or half a second of holding down 'T'.

    Some possibilities I've found from this board so far include kbhit(), GetAsyncKeyState, ::QueryPerformanceCounter(), ::QueryPerformanceFrequency(), and difftime.

    I plan on researching more about those now, but wanted to see if I'm on the right track or if perhaps anyone can direct me down a better path.

    Thanks again.

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    847
    This is posted in c++ but I can give you a sugestion that will work on windows since that is what you said you were using.
    Handle WM_KEYDOWN and call GetTickCount() when you receive WM_KEYUP call GetTickCount() again and compare to the previous time to calculate how long the key was held down.

  3. #3
    the Great ElastoManiac's Avatar
    Join Date
    Nov 2005
    Location
    Republika Srpska - Balkan
    Posts
    377
    I have a question too:

    When using WM_KEYDOWN, how can you know if thats the first time
    user has pressed key. You know, i only want to recive message once, and thats
    when the key is pressed.
    lParam has something to do with it, but i don't know exactly what...
    If you know the anwser please post an example.
    lu lu lu I've got some apples lu lu lu You've got some too lu lu lu Let's make some applesauce Take off our clothes and lu lu lu

  4. #4
    Registered User
    Join Date
    Nov 2005
    Posts
    4
    Thanks for the reply, Quantum1024.

    Since this may eventually be ported to windows, that'll quite helpful, but for now, it's a simple C++ program.

    I'll repost this on that section of the boards again since it's been moved.

  5. #5
    Registered User
    Join Date
    Jan 2005
    Posts
    847
    Quote Originally Posted by ElastoManiac
    I have a question too:

    When using WM_KEYDOWN, how can you know if thats the first time
    user has pressed key. You know, i only want to recive message once, and thats
    when the key is pressed.
    lParam has something to do with it, but i don't know exactly what...
    If you know the anwser please post an example.
    Bit 30 contains the previous key state so you could do this
    Code:
    if (HIWORD(lParam)&1)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Strange string behavior
    By jcafaro10 in forum C Programming
    Replies: 2
    Last Post: 04-07-2009, 08:38 PM
  2. Printing Length of Input and the Limited Input
    By dnguyen1022 in forum C Programming
    Replies: 33
    Last Post: 11-29-2008, 04:13 PM
  3. HELP!!!!emergency ~expert please help
    By unknowppl in forum C Programming
    Replies: 1
    Last Post: 08-19-2008, 08:35 AM
  4. Design layer question
    By mdoland in forum C# Programming
    Replies: 0
    Last Post: 10-19-2007, 05:22 AM
  5. Next Question...
    By Azmeos in forum C++ Programming
    Replies: 3
    Last Post: 06-06-2003, 03:40 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21