473,398 Members | 2,165 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,398 software developers and data experts.

SendKeys in ProcessCmdKey: change Shift-Space to just a Space

I'm trying to override the SHIFT-SPACE "negative feature" in the Winforms
datagrid, to only be a space.

The following link describes this:
http://www.dotnet247.com/247referenc...52/262224.aspx

In this procedure, MS suggested to use SendKeys.Send(" "), but I am finding
that this locks my machine, and SendWait() causes an infinite loop of
messages (stack overflow). How to convert a SHIFT-SPACE message to be just
a SPACE? Below is what I have.

------------------------------------

protected override bool ProcessCmdKey(ref Message msg, Keys keyData) {
Keys keyCode = (Keys) msg.WParam.ToInt32() & Keys.KeyCode;
if (msg.Msg == WM_KEYDOWN && keyCode == Keys.Space && Control.ModifierKeys
== Keys.Shift) {
byte[] keyStates = new byte[255];
GetKeyboardState(keyStates[0]); //load the keyboard
keyStates[16] = 0; // turn off the shift key
SetKeyboardState(keyStates[0]); //set the new keyboard state

// //**************
// // SendKeys doesn't work here. Locks the machine
// //**************
SendKeys.Send(" "); //boom
return true;
}
else
return base.ProcessCmdKey (ref msg, keyData);
}
Dec 14 '05 #1
1 8246
no takers?

that's ok... this solution is a little "hard-core" for me anyways...

it's funny that someone knew how to manipulate the keyboard state, but used
SendKeys to send the space, instead of manipulating the message directly.
I wonder why?

"John Richardson" <j3**********@hotmail.com> wrote in message
news:OZ**************@TK2MSFTNGP12.phx.gbl...
I'm trying to override the SHIFT-SPACE "negative feature" in the Winforms
datagrid, to only be a space.

The following link describes this:
http://www.dotnet247.com/247referenc...52/262224.aspx

In this procedure, MS suggested to use SendKeys.Send(" "), but I am
finding that this locks my machine, and SendWait() causes an infinite loop
of messages (stack overflow). How to convert a SHIFT-SPACE message to be
just a SPACE? Below is what I have.

------------------------------------

protected override bool ProcessCmdKey(ref Message msg, Keys keyData) {
Keys keyCode = (Keys) msg.WParam.ToInt32() & Keys.KeyCode;
if (msg.Msg == WM_KEYDOWN && keyCode == Keys.Space && Control.ModifierKeys
== Keys.Shift) {
byte[] keyStates = new byte[255];
GetKeyboardState(keyStates[0]); //load the keyboard
keyStates[16] = 0; // turn off the shift key
SetKeyboardState(keyStates[0]); //set the new keyboard state

// //**************
// // SendKeys doesn't work here. Locks the machine
// //**************
SendKeys.Send(" "); //boom
return true;
}
else
return base.ProcessCmdKey (ref msg, keyData);
}

Dec 20 '05 #2

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

Similar topics

2
by: orekinbck | last post by:
Hi There In a C# windows app in .NET 2003, I would like to capture when the user is within a certain text box and holds down shift then presses tab. Atm, my code is: protected override bool...
0
by: Gene Hubert | last post by:
I've got this working but I've got to wonder if there's not a better way. I'm capturing the tab and shift-tab keys in a datagrid and doing custom processing. Also, the form designer gets...
2
by: Wally Highsmith | last post by:
keyData == (Keys.Control | Keys.Shift | Keys.L) used to trap this combination in the ProcessDialogKey method Why does this combination no longer work?
5
by: Daniel N. | last post by:
I am trying have an application hold down the Shift key (+) and the Alt key (%) simultaneously for a given period of time, or until a condition is met. I tried this but it doesn't work:...
3
by: Rich | last post by:
Hello, I need to add a shift-F2 function to textboxes to bring up a dialogform with the expanded text contained in the respective Textbox. On any of the keydown events of a textbox I can only...
2
by: sytemper | last post by:
I write a keydown KeyDown event to catch if tab is press or tab+shift is press.And i already override the IsInputKey method. But noe i only can get the tab but no shift+tab. When shift+tab is...
5
by: sierra7 | last post by:
Hi I have often wanted to allow users to double-click on a control to open the Zoom window, instead of having to revert to the Shift +F2 keyboard method. The command SendKeys "+{F2}" works for...
5
by: Peted | last post by:
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...
2
by: Trooper | last post by:
Hi! I need help with calling ProcessCmdKey. I'm little bit confused how to use this method from my app. How to call it, from where? Can somebody explain to me? Thnx. This is the source:
0
by: dfemery | last post by:
I am writing a program that uses a third-party library of routines and methods to receive and display video from an S-Video source through a USB video capture device. That part works perfectly. There...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.