Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > General Coding
You last visited: Today at 18:42

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



PostMessage() VK_SHIFT

Discussion on PostMessage() VK_SHIFT within the General Coding forum part of the Coders Den category.

Reply
 
Old   #1
 
elite*gold: 0
Join Date: Jan 2014
Posts: 24
Received Thanks: 7
PostMessage() VK_SHIFT

I am trying to send the SHIFT key to another application, and then PostMessage() my characters so they show up in their shift key states.

The target process must run in the background, so setting the focus to it is not possible. Meaning SetForegroundWindow(), GetForegroundWindow(), SentInput(), keybd_event(), SendKeys() will not work.

I have seen some examples of SetKeyboardState() and I have used AttachThreadInput() to attach my thread to the thread of the target process, then SetKeyboardState() to press the SHIFT key, then detach my thread.

The target process still does not recognise my the SHIFT key being pressed.

Code:
// Send keystrokes to provided window handle using PostMessage API
DWORD SendKeys(HWND hWnd, char ch, DWORD pause)
{
	short vkChar;
	short vkState;
	DWORD dwDuration = 0;
	BYTE kbState[256];
	DWORD dwTargetId = 0;
	DWORD dwThisId = 0;

	vkChar = LOBYTE(VkKeyScan(ch)); // Scan code for selected key
	vkState = HIBYTE(VkKeyScan(ch));

	if ( vkState |= VKSC_SHIFT )
	{
		BYTE kbState[256];
		DWORD dwTargetId, dwThisId;

		memset(kbState, 0, sizeof(kbState));
		GetKeyboardState(kbState);
		kbState[VK_SHIFT] |= 0x80;

		dwTargetId = GetWindowThreadProcessId(hWnd, NULL);
		dwThisId = GetCurrentProcessId();

		if ( dwTargetId != dwThisId )
			AttachThreadInput(dwTargetId, dwThisId, TRUE);

		SetKeyboardState(kbState);
	}

	PostMessage(hWnd, WM_KEYDOWN, (WPARAM)vkChar,
		(LPARAM)CreateLParam(0, MapVirtualKey(vkChar, MAPVK_VK_TO_VSC), FALSE, FALSE));
	Sleep(pause);
	PostMessage(hWnd, WM_KEYUP, (WPARAM)vkChar,
		(LPARAM)CreateLParam(1, MapVirtualKey(vkChar, MAPVK_VK_TO_VSC), TRUE, TRUE));

	if ( vkState |= VKSC_SHIFT )
	{
		kbState[VK_SHIFT] &= 0x00;

		SetKeyboardState(kbState);

		if ( dwTargetId != dwThisId )
			AttachThreadInput(dwTargetId, dwThisId, FALSE);
	}

	return pause;
}
pushbyte is offline  
Reply

Tags
postmessage, setkeyboardstate, shift


Similar Threads Similar Threads
PostMessage UDF
06/27/2017 - AutoIt - 48 Replies
Benötigt wird mindestens AutoIt v3.3.8.1. Die UDF beinhaltet 9 Funktionen: _PostMessage_Send($hWnd, $Key, $Delay = 10) _PostMessage_SendDown($hWnd, $Key, $Delay = 10) _PostMessage_SendUp($hWnd, $Key, $Delay = 10) _PostMessage_Click($hWnd, $X = -1, $Y = -1, $Button = "left", $Clicks = 1, $Delay = 10) _PostMessage_ClickDown($hWnd, $X = -1, $Y = -1, $Button = "left") _PostMessage_ClickUp($hWnd, $X = -1, $Y = -1, $Button = "left") _PostMessage_ClickDrag($hWnd, $X1, $Y1, $X2, $Y2, $Button...
[C#]PostMessage problem.
01/16/2014 - .NET Languages - 6 Replies
Ich bin gerade dabei einen kleinen Bot für ein Spiel (DirectX App) zu schreiben. public static extern int PostMessage(IntPtr hwnd, uint wMsg, int wParam, int lParam); static extern uint GetLastError(); public static Process processes = Process.GetProcessesByName("game.bin");
C# - SendMessage/PostMessage
12/21/2013 - CO2 Programming - 3 Replies
Hello, I have recently started to toy around with the idea of sending a mouse click, or other events, to a conquer client that is minimized, or just not in focus. I have been using Spy++ to help along in all the messages the client receives and what not. I have got it kind of working and was wondering if anyone here could give me a hand. //WM_PARENTNOTIFY-SendMessage-ParentWindow bool seven = MouseClickHandler.SendMessage(new IntPtr(0x004F04CA), (int)0x0210, new IntPtr(0x00000201), new...
PostMessage / SendMessage (C#)
06/23/2013 - CO2 Programming - 2 Replies
I am trying to send key presses & mouse presses to the conquer window using PostMessage in C# but Conquer doesn't seem to respond to anything I send it. I am able to send key presses correctly to windows calculator though. Just wondering if anyone has had success using PostMessage / SendMessage and would be kind enough to share. Is there any other way to send key presses / mouse clicks while the conquer window is minimized? Thanks for any help :)
[Help] Postmessage
04/29/2011 - AutoIt - 15 Replies
Hallo, ich habe seit kurzem gelesen, dass es sowas wie Postmessage gibt und wollte mich mal ein bisschen damit befassen. Leider fand ich nichts hilfreiches(für mich zmd). Kann mir wer da helfen? Hab die Postmessage UDF auch schon.... MfG Ludder231



All times are GMT +1. The time now is 18:43.


Powered by vBulletin®
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2025 elitepvpers All Rights Reserved.