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

J

John Richardson

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/247reference/msgs/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);
}
 
J

John Richardson

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top