Jump to content
  • Advertisement
Sign in to follow this  
soconne

PostMessage and simulating Ctrl + A

This topic is 3738 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!