-
March 15th, 2004, 10:48 AM
#1
Keyboard state on MouseDown?
I may just be missing a simple call; but how do I find out if the shift, ctrl, and or alt keys are pressed when the mouse is clicked? For example, I may want to click on several objects on the screen, if the shift key is down I want to add the clicked object to the selection, but if not, I want to replace the selection with the newly clicked item. I've got everything I need to do this, but I don't know how to find out if the shift key is down when the click happens (without resorting to win32 api calls).
bytz
--This signature left intentionally blank--
-
March 15th, 2004, 12:33 PM
#2
Code:
if ((Control.ModifierKeys & Keys.Shift) == Keys.Shift)
-
March 15th, 2004, 01:34 PM
#3
Thanks, I appreciate the reply.
I just found that after searching through reams of code...
bytz
--This signature left intentionally blank--
-
March 17th, 2004, 10:29 PM
#4
Hi,
I just think if I want to check whether 2 control keys are pressed at the same time.
how can I do then?
if ((Control.ModifierKeys & Keys.Shift ) == Keys.Shift)
the code is just checking one ModifierKeys.
Should I need to do it in 2 if-loop? or any best way?
if ((Control.ModifierKeys & Keys.Shift ) == Keys.Shift)
{
if ((Control.ModifierKeys & Keys.Control) == Keys.Control)
.....
}
Thanks
Ee.... Sugoi Ne~~
-
March 18th, 2004, 02:52 AM
#5
Code:
if ((Control.ModifierKeys & Keys.Shift ) == Keys.Shift)
This is just checking that at least the Shift key is pressed not just the Shift key pressed.
So similarly for "Shift + Control" you have a choice of "at least" or "just" those keys pressed.
Code:
if ((Control.ModifierKeys & (Keys.Shift | Keys.Control)) == (Keys.Shift | Keys.Control))
OR
Code:
if (Control.ModifierKeys == (Keys.Shift | Keys.Control))
-
March 18th, 2004, 08:13 AM
#6
I actually prefer to do this:
Code:
bool isCtrl = (Control.ModifierKeys & Keys.Control) == Keys.Control;
bool isShift = (Control.ModifierKeys & Keys.Shift) == Keys.Shift;
This allows you to ues the values later:
Code:
if (isCtrl && isShift)
{
}
else
{
if (isShift)
}
bytz
--This signature left intentionally blank--
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|