By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,949 Members | 1,511 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,949 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.