Difference between right and left control/shift
-
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?
-
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?
-
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?
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.
-
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?
Hi again, thanks for your replies.
KeyEventArgs.Modifiers
can't discern left and right controls, I tried. The same concernsWM_KEYDOWN
. 'Wparam' value passed withWM_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()
andGetKeyState()
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? -
Hi again, thanks for your replies.
KeyEventArgs.Modifiers
can't discern left and right controls, I tried. The same concernsWM_KEYDOWN
. 'Wparam' value passed withWM_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()
andGetKeyState()
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?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
-
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
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.
-
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.
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
-
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
-
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