Groups | Blog | Home
all groups > dotnet general > february 2007 >

dotnet general : How to trap "ctl + c" in key up event


moondaddy
2/27/2007 10:55:10 PM
I writing a WPF windows app in c# and want to determine if the user has
pressed the control key and the 'c' key at the same time similar to the
standard windows 'copy' shortcut keys. How would I go about this?

Thanks.

--
moondaddy@noemail.noemail

v-lliu NO[at]SPAM online.microsoft.com
2/28/2007 12:00:00 AM
Hi,

Thank you for posting here.

This is a quick note to let you know that I am researching on this issue
and will get back to you ASAP. I appreciate your patience.


Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
v-lliu NO[at]SPAM online.microsoft.com
3/2/2007 4:10:53 AM
Hi,

Sorry for my delayed response.

To determine if the user has pressed the control key and the 'c' key at the
same time on a WPF window, we could subscribe the KeyDown event of the
window and check the pressed keys in the event handler.

The following is a sample.
public partial class Window1 : System.Windows.Window
{

public Window1()
{
InitializeComponent();
this.KeyDown += new KeyEventHandler(Window1_KeyDown);
}

void Window1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyboardDevice.Modifiers == ModifierKeys.Control && e.Key
== Key.C)
{
MessageBox.Show("You have pressed Ctrl+C.");
}
}
}

Hope this helps.
If you have any question, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support
AddThis Social Bookmark Button