Quantcast

Jump to content

» «
Photo

C++ How to detect multiple key presses, the second one being a JUST pr

4 replies to this topic
LetsPlayOrDy
  • LetsPlayOrDy

    Too fast for ya

  • Members
  • Joined: 24 Aug 2013
  • United-States

#1

Posted 29 April 2014 - 09:12 PM Edited by LetsPlayOrDy, 29 April 2014 - 09:14 PM.

Hi guys, I'd like to know how to detect multiple keys at the same time, but one being a key down, and the other a key press. So, if I pressed CTRL + N for example, it would do some code, but it wouldn't keep repeating.

I know how to detect a key down (GetAsyncKeyState), but not a key press. I've tried a way that I found, but it didn't work (http://gamedev.stack...-once-per-press (first answer, and I changed some of the code to be GetAsyncKeyState instead of whatever else it was) )

 

And for any of you .NET coders, here is the code I would use in C#. I'd like to basically convert this to C++.

void Test_KeyDown(object sender, GTA.KeyEventArgs e)

        {
            if (isKeyPressed(Keys.Control) && e.Key == Keys.N)
            {
                someFunction();
            }
        }

 

(P.S. I'm a slight noob at C++, so don't get mad at me if I don't understand something)

 

Thanks for your help :)


julionib
  • julionib

    Coder

  • Feroci Racing
  • Joined: 13 Sep 2012
  • Brazil

#2

Posted 01 May 2014 - 11:22 AM

what key combination you want detect?


nixolas1
  • nixolas1

    Creator/Destroyer

  • Members
  • Joined: 23 Dec 2008
  • None

#3

Posted 08 May 2014 - 10:03 AM

I would use this:

if ( GetKeyState(VK_LCONTROL)<0 && GetKeyState(0x46)<0 ){

For normal letter keys you have to use its virtual key value (google it).


LetsPlayOrDy
  • LetsPlayOrDy

    Too fast for ya

  • Members
  • Joined: 24 Aug 2013
  • United-States

#4

Posted 08 May 2014 - 12:55 PM Edited by LetsPlayOrDy, 08 May 2014 - 12:55 PM.

what key combination you want detect?

Something like CTRL + N.

 

 

I would use this:

if ( GetKeyState(VK_LCONTROL)<0 && GetKeyState(0x46)<0 ){

For normal letter keys you have to use its virtual key value (google it).

But wouldn't that be a key down? I would just like to detect if CTRL is down and A is pressed. 


XForceP
  • XForceP

    C++ Evangelist

  • Members
  • Joined: 04 Sep 2013
  • Germany

#5

Posted 08 May 2014 - 01:13 PM Edited by XForceP, 08 May 2014 - 01:13 PM.

You could subclass the window and use the Key events in the Message Queue





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users