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. Windows Forms
  4. Difference between right and left control/shift

Difference between right and left control/shift

Scheduled Pinned Locked Moved Windows Forms
helptutorialquestion
9 Posts 3 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.
  • P Offline
    P Offline
    pbalaga
    wrote on last edited by
    #1

    Hello, when a key is pressed in a win form, it receives "key down" message. That event can be traced in WndProc function where another parameter indicates what key was pressed. But the problem is discerning the left and the right control, shift or alt keys. Do you know how to find out whether right or left key was pressed?

    W A P 3 Replies Last reply
    0
    • P pbalaga

      Hello, when a key is pressed in a win form, it receives "key down" message. That event can be traced in WndProc function where another parameter indicates what key was pressed. But the problem is discerning the left and the right control, shift or alt keys. Do you know how to find out whether right or left key was pressed?

      W Offline
      W Offline
      Wendelius
      wrote on last edited by
      #2

      As far as I know there's no visible difference on left and right shift keys in .net event data. However, you can try using native WM_KEYDOWN notification and see if it shows the difference.

      1 Reply Last reply
      0
      • P pbalaga

        Hello, when a key is pressed in a win form, it receives "key down" message. That event can be traced in WndProc function where another parameter indicates what key was pressed. But the problem is discerning the left and the right control, shift or alt keys. Do you know how to find out whether right or left key was pressed?

        A Offline
        A Offline
        Alan N
        wrote on last edited by
        #3

        Hi Paul, I think you can find the information you need by coding a KeyDown event handler and examining the KeyEventArgs.Modifiers property. This returns a bitwise combination of values from the Keys enumeration which differentiates the right and left keys. The Alt keys are named LMenu and RMenu so you might easily miss those if you don't read the Keys documentation really carefully. Alan. [EDIT] Just tested this and the modifiers property doesn't return the left and right information, just plain Keys.Control, Keys.Alt etc.

        1 Reply Last reply
        0
        • P pbalaga

          Hello, when a key is pressed in a win form, it receives "key down" message. That event can be traced in WndProc function where another parameter indicates what key was pressed. But the problem is discerning the left and the right control, shift or alt keys. Do you know how to find out whether right or left key was pressed?

          P Offline
          P Offline
          pbalaga
          wrote on last edited by
          #4

          Hi again, thanks for your replies. KeyEventArgs.Modifiers can't discern left and right controls, I tried. The same concerns WM_KEYDOWN. 'Wparam' value passed with WM_KEYDOWN is surprisingly identical not only for e.g. control key. I'm wondering why pressing right alt (RMenu) resulted in the same event code as pressing a control key. However, I came across some info about native methods in winapi programming, with which left and right keys can be discerned. These are: GetAsyncKeyState() and GetKeyState() They return the state of a certain key with needed distinction. With some indirect code, it is possible to find out whether left or right key was pressed. But there comes the problem again (mentioned above): when I press right alt, firstly, the WndProc method gets a message as if the left control was pressed. Secondly, a KeyDown message for right alt is passed. Why is that so strange?

          W 1 Reply Last reply
          0
          • P pbalaga

            Hi again, thanks for your replies. KeyEventArgs.Modifiers can't discern left and right controls, I tried. The same concerns WM_KEYDOWN. 'Wparam' value passed with WM_KEYDOWN is surprisingly identical not only for e.g. control key. I'm wondering why pressing right alt (RMenu) resulted in the same event code as pressing a control key. However, I came across some info about native methods in winapi programming, with which left and right keys can be discerned. These are: GetAsyncKeyState() and GetKeyState() They return the state of a certain key with needed distinction. With some indirect code, it is possible to find out whether left or right key was pressed. But there comes the problem again (mentioned above): when I press right alt, firstly, the WndProc method gets a message as if the left control was pressed. Secondly, a KeyDown message for right alt is passed. Why is that so strange?

            W Offline
            W Offline
            Wendelius
            wrote on last edited by
            #5

            Good to know. Did you check lParam if WM_KeyDown. I understood from documentation that it should show the difference: lParam ... 24 Specifies whether the key is an extended key, such as the right-hand ALT and CTRL keys that appear on an enhanced 101- or 102-key keyboard. The value is 1 if it is an extended key; otherwise, it is 0. Mika

            P 1 Reply Last reply
            0
            • W Wendelius

              Good to know. Did you check lParam if WM_KeyDown. I understood from documentation that it should show the difference: lParam ... 24 Specifies whether the key is an extended key, such as the right-hand ALT and CTRL keys that appear on an enhanced 101- or 102-key keyboard. The value is 1 if it is an extended key; otherwise, it is 0. Mika

              P Offline
              P Offline
              pbalaga
              wrote on last edited by
              #6

              Can you let me know where did you find that information? Well, there is a difference but the value is never 1. For instance, on right alt down, there are two stages as I described. At first lparam = 1900545. Nextly, it is 557318145. Can it be dependent on the keyboard type? However you've got a point. I'll put more attention to lparam. But still, I don't know why pressing right alt causes sending two separate keydown messages. First for control, then for alt.

              W 1 Reply Last reply
              0
              • P pbalaga

                Can you let me know where did you find that information? Well, there is a difference but the value is never 1. For instance, on right alt down, there are two stages as I described. At first lparam = 1900545. Nextly, it is 557318145. Can it be dependent on the keyboard type? However you've got a point. I'll put more attention to lparam. But still, I don't know why pressing right alt causes sending two separate keydown messages. First for control, then for alt.

                W Offline
                W Offline
                Wendelius
                wrote on last edited by
                #7

                Sure: WM_KEYDOWN Notification[^] The value depends on many factors so the number may be significantly different at different keystrokes (or when the key is repeated and so on) I'm not absolutely sure about this but I've understood that right Alt isn't only alt but it's combination of Alt+Ctrl (that is also the reason for naming it Alt Gr and not only Alt) Mika

                P 1 Reply Last reply
                0
                • W Wendelius

                  Sure: WM_KEYDOWN Notification[^] The value depends on many factors so the number may be significantly different at different keystrokes (or when the key is repeated and so on) I'm not absolutely sure about this but I've understood that right Alt isn't only alt but it's combination of Alt+Ctrl (that is also the reason for naming it Alt Gr and not only Alt) Mika

                  P Offline
                  P Offline
                  pbalaga
                  wrote on last edited by
                  #8

                  Now I see what they mean with those numbers and value of 1. It is about specified bits inside lparam. No wonder that it has stranges values. You've helped me much so far, thanks. I'll post here when I come to something reasonable. Paul

                  W 1 Reply Last reply
                  0
                  • P pbalaga

                    Now I see what they mean with those numbers and value of 1. It is about specified bits inside lparam. No wonder that it has stranges values. You've helped me much so far, thanks. I'll post here when I come to something reasonable. Paul

                    W Offline
                    W Offline
                    Wendelius
                    wrote on last edited by
                    #9

                    You're welcome :) I'd be glad to hear when you resolve your problem or if new problems arise Mika

                    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