473,800 Members | 2,640 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(r ef 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.ProcessCmd Key(ref msg, keyData);
}
Apr 6 '08 #1
5 6160
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
384
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 myDataGrid.Select(rowNum); MessageBox.Show is coming up, but this takes no effect on Select or Focus. Anybody knows why?
2
5274
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
6181
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 the Form.KeyPress event does not trigger anymore. A way to 'solve' this is to set the focus to the form, but during testing it happens ofter the keypress event is not getting triggered on keys like
4
2544
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 information from a drop down box. The second datagrid is populated by viewing details from a row of the first datagrid. When editing individual rows (in either datagrid), clicking the enter key in any editable textbox calls my inital search...
10
27897
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? Tim
4
1572
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 MDI child form I can select an object and its properties are displayed in the properties window. All good so far. If I click in the properties window to edit the properties of my object, I
3
3828
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
5561
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 cell. I'm trying to figure out how to capture the Enter key so to run the buttoncontrol click function. I can get this to work when the datagrid only is activated (by clicking on the whitespace of the grid) but of course it won't work when the cursor...
4
3821
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
9690
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9551
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10504
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10251
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
5469
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5606
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4149
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2945
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.