PC Review


Reply
Thread Tools Rate Thread

C# Form Handeling Multi-key press

 
 
Kbalz
Guest
Posts: n/a
 
      12th Feb 2007
I have a Form that is performing a wizard-like step system (using
TabControl), and I need a key combination (like ControlKey + A + T) to
be caught and show a secret admin TabPage.

I tried to add an event handler to the form to catch a key that I
press and change a label to the key I press with this code:


Code:
private void AdminKeyboardEvent(object sender, KeyEventArgs e)
{
lblDebug.Text = e.KeyCode.ToString();
}

However I read on some other sites that my TabControl was preventing
my Form from ever getting these key inputs.. so I had to add
"this.KeyPreview = true;" in my Form contructor..

Now my form is properly handeling a single key stroke, but how can I
get it to handel the user press 2 or 3 keys at the same time?

C#.NET 2.0 using VS2005.

 
Reply With Quote
 
 
 
 
Kbalz
Guest
Posts: n/a
 
      12th Feb 2007
On Feb 12, 10:19 am, "Kbalz" <kbalc...@edge-sweets.com> wrote:
> I have a Form that is performing a wizard-like step system (using
> TabControl), and I need a key combination (like ControlKey + A + T) to
> be caught and show a secret admin TabPage.
>
> I tried to add an event handler to the form to catch a key that I
> press and change a label to the key I press with this code:
>
> Code:
> private void AdminKeyboardEvent(object sender, KeyEventArgs e)
> {
> lblDebug.Text = e.KeyCode.ToString();
> }
>
> However I read on some other sites that my TabControl was preventing
> my Form from ever getting these key inputs.. so I had to add
> "this.KeyPreview = true;" in my Form contructor..
>
> Now my form is properly handeling a single key stroke, but how can I
> get it to handel the user press 2 or 3 keys at the same time?
>
> C#.NET 2.0 using VS2005.


This seems to work so far, Control + X

private void AdminKeyboardEvent(object sender, KeyEventArgs
e)
{
lblDebug.Text = e.KeyCode.ToString();
if (ModifierKeys.Equals(Keys.Control) &
e.KeyCode.Equals(Keys.X))
lblDebug.Text = "enter admin window";
}

 
Reply With Quote
 
Ben Voigt
Guest
Posts: n/a
 
      12th Feb 2007

>> Now my form is properly handeling a single key stroke, but how can I
>> get it to handel the user press 2 or 3 keys at the same time?
>>


Use KeyDown and KeyUp instead of KeyPress, or P/Invoke GetKeyboardState.
You may also want to check that other keys are NOT simultaneously pressed,
to keep someone from getting in by just mashing half the keyboard.


 
Reply With Quote
 
Kbalz
Guest
Posts: n/a
 
      13th Feb 2007
On Feb 12, 6:35 pm, "Ben Voigt" <r...@nospam.nospam> wrote:
> >> Now my form is properly handeling a single key stroke, but how can I
> >> get it to handel the user press 2 or 3 keys at the same time?

>
> Use KeyDown and KeyUp instead of KeyPress, or P/Invoke GetKeyboardState.
> You may also want to check that other keys are NOT simultaneously pressed,
> to keep someone from getting in by just mashing half the keyboard.


Hopefully my software isn't that frustrating that users would do
that!! That is a great suggestion though, thanks!

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need some help on some text handeling adam_kroger@hotmail.com Microsoft Excel Misc 2 18th Jul 2007 07:32 AM
Calling a form from another form's button press gordon Microsoft C# .NET 1 27th Jul 2006 11:19 AM
events handeling juli Microsoft C# .NET 1 25th Jan 2005 03:57 PM
.tif file handeling Greg Windows XP Internet Explorer 1 6th Oct 2004 06:02 PM
Can i check user press the <enter> key in multi-line textbox? Chad Z. Hower aka Kudzu Microsoft ASP .NET 1 23rd Jan 2004 11:10 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:37 AM.