Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to get ALT, SHIFT and CTRL key?

How to get ALT, SHIFT and CTRL key?

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelptutorial
10 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    TooShy2Talk
    wrote on last edited by
    #1

    Hi, I want to get ALT, SHIFT and CTRL key from keyboard. Is it possible in OnKeyDown event? How can I do it? Hope you can help me. Thanks.

    E M 2 Replies Last reply
    0
    • T TooShy2Talk

      Hi, I want to get ALT, SHIFT and CTRL key from keyboard. Is it possible in OnKeyDown event? How can I do it? Hope you can help me. Thanks.

      E Offline
      E Offline
      Eytukan
      wrote on last edited by
      #2

      OnSysKeyDown


      OK,. what country just started work for the day ? The ASP.NET forum is flooded with retarded questions. -Christian Graus Best wishes to Rexx[^]

      T 1 Reply Last reply
      0
      • E Eytukan

        OnSysKeyDown


        OK,. what country just started work for the day ? The ASP.NET forum is flooded with retarded questions. -Christian Graus Best wishes to Rexx[^]

        T Offline
        T Offline
        TooShy2Talk
        wrote on last edited by
        #3

        Thanks for the reply. I think it's the same function as OnKeyDown(). Can I monitor SHIFT and CTRL with it?

        E 1 Reply Last reply
        0
        • T TooShy2Talk

          Thanks for the reply. I think it's the same function as OnKeyDown(). Can I monitor SHIFT and CTRL with it?

          E Offline
          E Offline
          Eytukan
          wrote on last edited by
          #4

          Sorry ignore my previous reply. It's for ATL combination keys. Clickety[^]


          OK,. what country just started work for the day ? The ASP.NET forum is flooded with retarded questions. -Christian Graus Best wishes to Rexx[^]

          1 Reply Last reply
          0
          • T TooShy2Talk

            Hi, I want to get ALT, SHIFT and CTRL key from keyboard. Is it possible in OnKeyDown event? How can I do it? Hope you can help me. Thanks.

            M Offline
            M Offline
            Mahesh Kulkarni
            wrote on last edited by
            #5
                `BOOL bCtrl = ::GetKeyState(VK_CONTROL); 	BOOL bAlt = ::GetKeyState(VK_SHIFT); 	BOOL bShift = ::GetKeyState(VK_MENU);`
            

            This will help you to know the combination keydown tracking.

            The secret of life is not enjoyment but education through experience. - Swami Vivekananda.

            T T 3 Replies Last reply
            0
            • M Mahesh Kulkarni
                  `BOOL bCtrl = ::GetKeyState(VK_CONTROL); 	BOOL bAlt = ::GetKeyState(VK_SHIFT); 	BOOL bShift = ::GetKeyState(VK_MENU);`
              

              This will help you to know the combination keydown tracking.

              The secret of life is not enjoyment but education through experience. - Swami Vivekananda.

              T Offline
              T Offline
              ThatsAlok
              wrote on last edited by
              #6

              Mahesh Kulkarni wrote:

              BOOL bCtrl = ::GetKeyState(VK_CONTROL); BOOL bAlt = ::GetKeyState(VK_SHIFT); BOOL bShift = ::GetKeyState(VK_MENU);

              though it is the nice way to get key state, but you have poll this thing every time to get state of the key.,

              "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
              Never mind - my own stupidity is the source of every "problem" - Mixture

              cheers, Alok Gupta VC Forum Q&A :- I/IV Support CRY- Child Relief and You/codeProject$$>

              M 1 Reply Last reply
              0
              • T ThatsAlok

                Mahesh Kulkarni wrote:

                BOOL bCtrl = ::GetKeyState(VK_CONTROL); BOOL bAlt = ::GetKeyState(VK_SHIFT); BOOL bShift = ::GetKeyState(VK_MENU);

                though it is the nice way to get key state, but you have poll this thing every time to get state of the key.,

                "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
                Never mind - my own stupidity is the source of every "problem" - Mixture

                cheers, Alok Gupta VC Forum Q&A :- I/IV Support CRY- Child Relief and You/codeProject$$>

                M Offline
                M Offline
                Mahesh Kulkarni
                wrote on last edited by
                #7

                Yes alok I do agree with u. But I got only this solution to do this....if any alternative for this please tell.

                The secret of life is not enjoyment but education through experience. - Swami Vivekananda.

                1 Reply Last reply
                0
                • M Mahesh Kulkarni
                      `BOOL bCtrl = ::GetKeyState(VK_CONTROL); 	BOOL bAlt = ::GetKeyState(VK_SHIFT); 	BOOL bShift = ::GetKeyState(VK_MENU);`
                  

                  This will help you to know the combination keydown tracking.

                  The secret of life is not enjoyment but education through experience. - Swami Vivekananda.

                  T Offline
                  T Offline
                  TooShy2Talk
                  wrote on last edited by
                  #8

                  Thank you for the reply. I will try this now.

                  1 Reply Last reply
                  0
                  • M Mahesh Kulkarni
                        `BOOL bCtrl = ::GetKeyState(VK_CONTROL); 	BOOL bAlt = ::GetKeyState(VK_SHIFT); 	BOOL bShift = ::GetKeyState(VK_MENU);`
                    

                    This will help you to know the combination keydown tracking.

                    The secret of life is not enjoyment but education through experience. - Swami Vivekananda.

                    T Offline
                    T Offline
                    TooShy2Talk
                    wrote on last edited by
                    #9

                    I tried your code inside OnKeyDown() event but the result is unpredictable. if(::GetKeyState(VK_CONTROL)) AfxMessageBox(L"CONTROL"); if(::GetKeyState(VK_SHIFT)) AfxMessageBox(L"SHIFT"); if(::GetKeyState(VK_MENU)) AfxMessageBox(L"ALT"); When ALT is pressed, either no display or wrong message(CONTROL or SHIFT) CONTROL and SHIFT sometimes correct but sometimes display all. Did i do something wrong? How will i use the code?

                    M 1 Reply Last reply
                    0
                    • T TooShy2Talk

                      I tried your code inside OnKeyDown() event but the result is unpredictable. if(::GetKeyState(VK_CONTROL)) AfxMessageBox(L"CONTROL"); if(::GetKeyState(VK_SHIFT)) AfxMessageBox(L"SHIFT"); if(::GetKeyState(VK_MENU)) AfxMessageBox(L"ALT"); When ALT is pressed, either no display or wrong message(CONTROL or SHIFT) CONTROL and SHIFT sometimes correct but sometimes display all. Did i do something wrong? How will i use the code?

                      M Offline
                      M Offline
                      Mahesh Kulkarni
                      wrote on last edited by
                      #10

                      Try this...

                            BOOL bCtrl = ::GetKeyState(VK_CONTROL)& 0x8000;
                            BOOL bShift = ::GetKeyState(VK_SHIFT)& 0x8000;
                            BOOL bAlt = ::GetKeyState(VK_MENU)& 0x8000 ;	
                      

                      The secret of life is not enjoyment but education through experience. - Swami Vivekananda.

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups