473,322 Members | 1,523 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,322 software developers and data experts.

traping all combinations of keypress in overriding ProcessCmdKey



Hello,

i am lookinf for the best way to trap any alphanumeric keypress in all
multi key combminations and execute some code

For example , i have a form visible using the form.showdialog method,
then the user can press keys A, D, E, F, T, and C to peform a
function.
What i want is that if a user presses A, or a, or SHIFT A or CNTRL A
that it executes the same code, BUT NOT IF ALT A is pressed. The same
applies for the other letters.

I am overriding the processcmdkey function using the code bellow, and
it works, but not for ALL the multi key combo's i present above.

Can anyone help me on how to trap all the key combos i want listed
above

thanks for any help

Peted

#region ProcessCmdKey
protected override bool ProcessCmdKey(ref Message msg, Keys
keyData)
{
const int WM_KEYDOWN = 0x100;
const int WM_SYSKEYDOWN = 0x104;

if ((msg.Msg == WM_KEYDOWN) || (msg.Msg == WM_SYSKEYDOWN))
{
switch (keyData)
{
case Keys.Tab:
//Do something
return true;
break;
case Keys.F3:
//Do something
return true;
break;

case Keys.A:
//Do something
return true;
case Keys.D:
//Do something
return true;

case Keys.E:
//Do something
return true;

case Keys.F:
//Do something
return true;

case Keys.T:
//Do something
return true;
case Keys.C:
//Do something
return true;

}
}
return base.ProcessCmdKey(ref msg, keyData);
}
Apr 6 '08 #1
5 6107
On Sun, 06 Apr 2008 09:40:16 -0700, <Petedwrote:
i am lookinf for the best way to trap any alphanumeric keypress in all
multi key combminations and execute some code

For example , i have a form visible using the form.showdialog method,
then the user can press keys A, D, E, F, T, and C to peform a
function.
What i want is that if a user presses A, or a, or SHIFT A or CNTRL A
that it executes the same code, BUT NOT IF ALT A is pressed. The same
applies for the other letters.

I am overriding the processcmdkey function using the code bellow, and
it works, but not for ALL the multi key combo's i present above.
Why not? What happens? What did you expect to happen instead?

Pete
Apr 6 '08 #2

>I am overriding the processcmdkey function using the code bellow, and
it works, but not for ALL the multi key combo's i present above.

Why not? What happens? What did you expect to happen instead?

Pressing A, D, E, F, T, and C keys on thier own works fine

Capslock and A, D, E, F, T, and C works fine

Shift and A, D, E, F, T, and C does not work

Control and A, D, E, F, T, and C does not work

Alt and A, D, E, F, T, and C does not work
(I have now decided i do want the alt key combo to also work)

So any idea how i can get mod the code to make it pick up all those
modifier and key press combo in addition to just pressing the relevant
letter ?

I want all those combos to execute the same code as the single
keypress

Any advice appreciated

thanks

Peted

Apr 7 '08 #3
Peted wrote:
>
Control and A, D, E, F, T, and C does not work
To capture Ctrl A separately, you would need
switch (keyData)
{
case (Keys.A | Keys.Control):

Keys combines the keys being pressed.


Apr 7 '08 #4
On Sun, 06 Apr 2008 18:39:37 -0700, <Petedwrote:
[...]
So any idea how i can get mod the code to make it pick up all those
modifier and key press combo in addition to just pressing the relevant
letter ?
Instead of "switch (keyData)" use "switch (keyData & Keys.KeyCode)". That
will filter out the modifier keys, leaving only the actual key pressed.

If you decide later that you want some modifier keys but not others, there
are a variety of ways you can check for that, but they all involve similar
techniques. That is, using the various mask constants in the Keys
enumeration to check specifically for modifiers.

Pete
Apr 7 '08 #5

Great, thanks heaps dude

Peted

>On Sun, 06 Apr 2008 18:39:37 -0700, <Petedwrote:
>[...]
So any idea how i can get mod the code to make it pick up all those
modifier and key press combo in addition to just pressing the relevant
letter ?

Instead of "switch (keyData)" use "switch (keyData & Keys.KeyCode)". That
will filter out the modifier keys, leaving only the actual key pressed.

If you decide later that you want some modifier keys but not others, there
are a variety of ways you can check for that, but they all involve similar
techniques. That is, using the various mask constants in the Keys
enumeration to check specifically for modifiers.

Pete
Apr 7 '08 #6

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

Similar topics

1
by: Susanne Christe | last post by:
Hi Folks, I'm trying to override protected ProcessCmdKey function in writing my a custom MyDataGrid. I get the Keys I want, but it takes no effect to MyDataGrid, if I try for example execute...
2
by: freddy | last post by:
How do I use the Keypress event. So if I hit in the Enter key I went it do someting. like instead of clicking on a button the enter key will fire up the program
1
by: Rene | last post by:
Hi, I am running is some problems with the KeyPreview and KeyPress events. The KeyPress event is only triggered when there this an focusable control on the form. When all controls are disabled...
4
by: jibran | last post by:
Hello. I have wrapped the DataGrid control with my own class (SmartDataGrid) adding some necessary functionality. My current webform has 2 SmartDataGrids. The first is populated by selected...
10
by: Tim Frawley | last post by:
I am attempting to detect a Shift+Tab in the KeyPress event for back navigation on a control that doesn't support this method. Does anyone have any ideas how to compare e.KeyChar to a ShiftTab? ...
4
by: Charles Law | last post by:
I have an MDI application which contains a menu, MDI child form and properties window. On my Edit menu I have Cut, Copy, Paste, and Delete. The shortcut key for Delete is set to Del. In the...
3
by: Phil Galey | last post by:
In VB6 you can block invalid keystrokes in the KeyPress event by setting KeyAscii = 0. How can you block invalid keystrokes in VB.NET?
2
by: chatelain | last post by:
Ok a couple things I've got going: On the DataGrid1_CurrentCellChanged I add a button control to the datagridtextbox. This occurs when a mouse click happens inside the cell or the cursor enters the...
4
by: =?Utf-8?B?R2lkaQ==?= | last post by:
Hi, In multiLine textBox, enter moves to the next line, how can i overwrite it, so enter will move to the next control and ctrl + enter will move to the next line? Thanks, Gidi.
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...
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: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
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: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.