473,320 Members | 1,955 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

C# Form Handeling Multi-key press

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.

Feb 12 '07 #1
3 14554
On Feb 12, 10:19 am, "Kbalz" <kbalc...@edge-sweets.comwrote:
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";
}

Feb 12 '07 #2
>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.
Feb 12 '07 #3
On Feb 12, 6:35 pm, "Ben Voigt" <r...@nospam.nospamwrote:
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!

Feb 13 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Leo J. Hart IV | last post by:
OK, here's another question for the experts: I am building a multi-step (3 steps actually) form using a panel for each step and hiding/displaying the appropriate panel/panels depending on which...
5
by: Olly | last post by:
Hello Everyone! Could someone please have a look at my JS Form I posted below....Something wrong there, but I don't understand what's exactly. Many thanks. Olly ...
13
by: abcdefghijklmnop | last post by:
I have a "Questions" form that reads off of a table and contains a multi-value field called "Keywords". I already know that having a multi-value field is a horrible idea, however, I am patching up a...
1
tolkienarda
by: tolkienarda | last post by:
hello wonderful people of java land i am writing a program and trying to check to make sure some of my inputs are valid integers. i was told that i needed to read into exception handeling and now...
1
by: ashruba | last post by:
I want to read inbox of nokia N72 through file handeling in c/c++ please give guidence.
1
by: =?Utf-8?B?Umljaw==?= | last post by:
Is there a way to create a windows form in c# 2005 with form size larger than the Maximum height of 876? If not then how do I create a multi-page contineous form?
9
by: shariquehabib | last post by:
Hi All, I want to get some values by reading a file (already created) through file handeling but dont want to get DUPLICATE values. How can i do that..plz help me out....... E.g: file name...
4
by: shariquehabib | last post by:
Hi All, I am using file handeling in C lang. Can anyone please let me know that how can i read spaces from a perticular file?? To read some values (strings) i m using fscanf func. Can...
11
by: woodey2002 | last post by:
This problem is driving me crazy. Hello there, i am trying to create a search form for records in my access database. The search form will contain text boxes and a multi select list box. The user...
2
by: woodey2002 | last post by:
Hi Guys and thanks for your time. I have a search form for my database that allows users to select multiple criteria from multi select list boxes. I successfully integrated a multi select...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.