Home All Groups Group Topic Archive Search About
Author
4 Apr 2005 2:05 PM
Barguast
When a control's 'Click' event is triggered, is there a way I can test
whether the CTRL / Alt / Shift keys are pressed as well? I've thought about
capturing KeyDown events before the click but this assumes that the control
is in focus which won't necessarily be so.

Author
4 Apr 2005 2:09 PM
Gabriel Lozano-Morán
You can capture this in the KeyDown() and KeyUp() event

Using either e.Modifiers or checking if e.Control || e.Shift || e.Alt equals
to true

Gabriel Lozano-Morán

Show quoteHide quote
"Barguast" <ItsLikeMadeUpNSt***@Email.com> wrote in message
news:7B0DA1F0-B310-4C06-9EAE-F6862ABC850D@microsoft.com...
> When a control's 'Click' event is triggered, is there a way I can test
> whether the CTRL / Alt / Shift keys are pressed as well? I've thought
> about
> capturing KeyDown events before the click but this assumes that the
> control
> is in focus which won't necessarily be so.
Are all your drivers up to date? click for free checkup

Author
4 Apr 2005 2:21 PM
Barguast
But as I said, the control won't necessarily be in focus when the CTRL / Alt
/ Shift key is pressed which means the KeyDown / KeyUp events won't be
triggered.

Show quoteHide quote
"Gabriel Lozano-Morán" wrote:

> You can capture this in the KeyDown() and KeyUp() event
>
> Using either e.Modifiers or checking if e.Control || e.Shift || e.Alt equals
> to true
>
> Gabriel Lozano-Morán
>
> "Barguast" <ItsLikeMadeUpNSt***@Email.com> wrote in message
> news:7B0DA1F0-B310-4C06-9EAE-F6862ABC850D@microsoft.com...
> > When a control's 'Click' event is triggered, is there a way I can test
> > whether the CTRL / Alt / Shift keys are pressed as well? I've thought
> > about
> > capturing KeyDown events before the click but this assumes that the
> > control
> > is in focus which won't necessarily be so.
>
>
>
Author
4 Apr 2005 2:31 PM
Pipo
Barguast,

You can capture the keyevents if you set the keypreview to true on the form.
That way when ever the form has the focus, you could get the Keys pressed.



Show quoteHide quote
"Barguast" <ItsLikeMadeUpNSt***@Email.com> wrote in message
news:ED944675-D284-4F73-85FF-9BF7BEF4EE4E@microsoft.com...
> But as I said, the control won't necessarily be in focus when the CTRL /
Alt
> / Shift key is pressed which means the KeyDown / KeyUp events won't be
> triggered.
>
> "Gabriel Lozano-Morán" wrote:
>
> > You can capture this in the KeyDown() and KeyUp() event
> >
> > Using either e.Modifiers or checking if e.Control || e.Shift || e.Alt
equals
> > to true
> >
> > Gabriel Lozano-Morán
> >
> > "Barguast" <ItsLikeMadeUpNSt***@Email.com> wrote in message
> > news:7B0DA1F0-B310-4C06-9EAE-F6862ABC850D@microsoft.com...
> > > When a control's 'Click' event is triggered, is there a way I can test
> > > whether the CTRL / Alt / Shift keys are pressed as well? I've thought
> > > about
> > > capturing KeyDown events before the click but this assumes that the
> > > control
> > > is in focus which won't necessarily be so.
> >
> >
> >
Author
4 Apr 2005 2:51 PM
Barguast
Thanks for yours replies, but I've just found out about the static
'System.Windows.Forms.ModifierKeys' property which can be checked during the
click event. For example:

private void Cell_Click (object sender, EventArgs e)
{
    if ((Control.ModifierKeys & Keys.Control) == Keys.Control)
    {
        // The control has been CTRL-Clicked
    }               
}

That'll do the trick :)

Show quoteHide quote
"Pipo" wrote:

> Barguast,
>
> You can capture the keyevents if you set the keypreview to true on the form.
> That way when ever the form has the focus, you could get the Keys pressed.
>
>
>
> "Barguast" <ItsLikeMadeUpNSt***@Email.com> wrote in message
> news:ED944675-D284-4F73-85FF-9BF7BEF4EE4E@microsoft.com...
> > But as I said, the control won't necessarily be in focus when the CTRL /
> Alt
> > / Shift key is pressed which means the KeyDown / KeyUp events won't be
> > triggered.
> >
> > "Gabriel Lozano-Morán" wrote:
> >
> > > You can capture this in the KeyDown() and KeyUp() event
> > >
> > > Using either e.Modifiers or checking if e.Control || e.Shift || e.Alt
> equals
> > > to true
> > >
> > > Gabriel Lozano-Morán
> > >
> > > "Barguast" <ItsLikeMadeUpNSt***@Email.com> wrote in message
> > > news:7B0DA1F0-B310-4C06-9EAE-F6862ABC850D@microsoft.com...
> > > > When a control's 'Click' event is triggered, is there a way I can test
> > > > whether the CTRL / Alt / Shift keys are pressed as well? I've thought
> > > > about
> > > > capturing KeyDown events before the click but this assumes that the
> > > > control
> > > > is in focus which won't necessarily be so.
> > >
> > >
> > >
>
>
>
Author
4 Apr 2005 3:29 PM
Morten Wennevik
Indeed, though it is not the Form's ModifierKeys, but Form inherits from 
Control so ...

There is also the static Control.MouseButtons.

--
Happy Coding!
Morten Wennevik [C# MVP]
Author
4 Apr 2005 2:45 PM
Gabriel Lozano-Morán
Sorry i totally misunderstood the question. Hope this can help you get
started:

[System.Runtime.InteropServices.DllImport("User32",
EntryPoint="GetKeyState", ExactSpelling=false,
CharSet=System.Runtime.InteropServices.CharSet.Ansi, SetLastError=true)]
private static extern int GetKeyState(long nVirtKey);
private const int VK_CONTROL = 0x11;
private void button1_Click(object sender, System.EventArgs e)
{
    MessageBox.Show(GetKeyState(VK_CONTROL).ToString());
}

Gabriel Lozano-Morán

Show quoteHide quote
"Barguast" <ItsLikeMadeUpNSt***@Email.com> wrote in message
news:ED944675-D284-4F73-85FF-9BF7BEF4EE4E@microsoft.com...
> But as I said, the control won't necessarily be in focus when the CTRL /
> Alt
> / Shift key is pressed which means the KeyDown / KeyUp events won't be
> triggered.
>
> "Gabriel Lozano-Morán" wrote:
>
>> You can capture this in the KeyDown() and KeyUp() event
>>
>> Using either e.Modifiers or checking if e.Control || e.Shift || e.Alt
>> equals
>> to true
>>
>> Gabriel Lozano-Morán
>>
>> "Barguast" <ItsLikeMadeUpNSt***@Email.com> wrote in message
>> news:7B0DA1F0-B310-4C06-9EAE-F6862ABC850D@microsoft.com...
>> > When a control's 'Click' event is triggered, is there a way I can test
>> > whether the CTRL / Alt / Shift keys are pressed as well? I've thought
>> > about
>> > capturing KeyDown events before the click but this assumes that the
>> > control
>> > is in focus which won't necessarily be so.
>>
>>
>>

Bookmark and Share