PostMessage and simulating Ctrl + A

Started by
2 comments, last by Deaken Frost 15 years, 9 months ago
I'm attempting to hook into Visual Studio and inject a keypress for Ctrl + A. So far I'm able to inject any single key press, but I am unable to simulate the pressing and holding down of any of the special keys: Control, Shift, Alt, ect... Here's my code so far, does anybody know how to properly do this?

        HWND vsWin = ::GetForegroundWindow();
	HWND mdiClient = ::FindWindowEx(vsWin, NULL, "MDIClient", NULL);
	HWND mdiContainer = ::FindWindowEx(mdiClient, NULL, "EzMdiContainer", NULL);
	HWND dockingView = ::FindWindowEx(mdiContainer, NULL, "DockingView", NULL);
	HWND genericPane = ::FindWindowEx(dockingView, NULL, "GenericPane", NULL);
	HWND splitterRoot = ::FindWindowEx(genericPane, NULL, "VsSplitterRoot", NULL);
	HWND editPane = ::FindWindowEx(splitterRoot, NULL, "VsEditPane", NULL);
	HWND textEditPane = ::FindWindowEx(editPane, NULL, "VsTextEditPane", NULL);

	if (textEditPane == NULL) cout << "null\n";
	else {
		DWORD tid = ::GetWindowThreadProcessId(textEditPane, NULL);
		::AttachThreadInput(::GetCurrentThreadId(), tid, true);

		BYTE ks[256];
		::GetKeyboardState(&ks[0]);
		ks[VK_RCONTROL] = 129;
		ks[VK_LCONTROL] = 129;
		::SetKeyboardState(ks);

		::PostMessage(textEditPane, WM_KEYDOWN, 'A', 0);

                ::AttachThreadInput(::GetCurrentThreadId(), tid, false);
       }

Author Freeworld3Dhttp://www.freeworld3d.org
Advertisement
A useful tool: MessageSender

Possibly useful discussions:

How to send a CTRL+X key to another window?

Big problem with simulating keypresses

Have you looked at WM_SYSKEYDOWN?
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man
SendInput Function
"Walk not the trodden path, for it has borne it's burden." -John, Flying Monk
I dont't know what you try to accomplish, but I think that writing a plug-in for Visual Studio might be the better solution.

This topic is closed to new replies.

Advertisement