471,613 Members | 1,895 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,613 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 7854
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.

Similar topics

2 posts views Thread by orekinbck | last post: by
reply views Thread by Gene Hubert | last post: by
5 posts views Thread by Daniel N. | last post: by
2 posts views Thread by sytemper | last post: by
2 posts views Thread by Trooper | last post: by
reply views Thread by leo001 | last post: by
1 post views Thread by ZEDKYRIE | last post: by

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.