Sign in to follow this  
soconne

PostMessage and simulating Ctrl + A

Recommended Posts

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);
       }

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this