views:

547

answers:

3

I want to make ^N work the same as Down arrow in a tree control. I thought I'd just have to add the following to the KeyDown handler:

SendKeys.Send("{Down}");

but this gets treated as a Control-Down arrow since the control key is currently pressed. The msdn page describes how to turn on the control modifier but not how to turn it off.

Thanks, Keith

A: 

Here's the hard way of doing it. I admit this is not the optimal way to do it. I'm sure you already know this. You might want to overload the WindProc method of the control & use SendMsg Win32 Api. This is how I used get things to work back in the day.

AB Kolan
A: 

You can p/invoke to keybd_event. That will let you simulate a key being both in "up" and "down" state.

danbystrom
+1  A: 

Sorry to come late to the party but I think I found a solution:

First, import SetKeyboardState:

[DllImport("user32.dll")]
public static extern bool SetKeyboardState(byte[] lpKeyState);

Then, just call it with a zeroed byte array before calling SendKeys.Send():

SetKeyboardState(new byte[256]);
SendKeys.Send("your key sequence");

That worked for me. Hope this helps!

+1 Worked for me too ;)
JustLoren