Keystroke emulation menu

User Tag List

Results 1 to 15 of 15
  1. #1
    Hrap's Avatar Active Member
    Reputation
    17
    Join Date
    Oct 2018
    Posts
    127
    Thanks G/R
    17/8
    Trade Feedback
    0 (0%)
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Keystroke emulation

    Hello,
    I ran into a keystroke emulation problem in WoW 3.3.5a.

    I first used WINAPI
    PostMessage
    but when the game window loses focus, pressing is no longer generated.
    I tried all possible WINAPI options, and no one works without focus

    I think I need something from WOW
    But how to implement it, I do not know yet


    I found the following
    00765AF0 OnKeyDown
    00764B90 OnKeyDownRepeat
    00763BE0 OnKeyUp

    as I understand, these events occur during keystrokes

    005FD3D0 InputControlDestroy_0
    005F9580 InputControlRegisterScriptFunctions
    00868D40 InputEvent
    CInputControl = 0x00C24954



    as I understand it, I need to use CInputControl or InputEvent
    Can you tell me how to implement keystroke emulation?
    At least in which direction to look.
    Thank you in advance

    Keystroke emulation
  2. #2
    ChrisIsMe's Avatar Contributor
    Reputation
    164
    Join Date
    Apr 2017
    Posts
    210
    Thanks G/R
    67/100
    Trade Feedback
    0 (0%)
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Code:
    SendInput in C++
    
    void sendKey(int key)
    {
    	INPUT ip;
    
    	ip.type = INPUT_KEYBOARD;
    	ip.ki.wScan = 0; 
    	ip.ki.time = 0;
    	ip.ki.dwExtraInfo = 0;
    
    	ip.ki.wVk = key; 
    	ip.ki.dwFlags = 0; 
    	SendInput(1, &ip, sizeof(INPUT));
    
    	ip.ki.dwFlags = KEYEVENTF_KEYUP;
    	SendInput(1, &ip, sizeof(INPUT));
    }
    
    PostMessage in C#
    
            public static void FakeKey(int key)
            {
                PostMessage(Application().MainWindowHandle, WM_KEYDOWN, key, 0);
                PostMessage(Application().MainWindowHandle, WM_KEYUP, key, 0);
            }
    With those examples, postmessage would send it to the process if in foreground or not, sendinput will send the keystroke to where ever your active application is, so you would want to use something to check foreground.
    Last edited by ChrisIsMe; 11-04-2018 at 04:17 PM.

  3. #3
    Hrap's Avatar Active Member
    Reputation
    17
    Join Date
    Oct 2018
    Posts
    127
    Thanks G/R
    17/8
    Trade Feedback
    0 (0%)
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    SendImput is not working

    Code:
    	void GenerateKey(int vk) {
    
    		LPARAM lParam;
    		int ScanCode = MapVirtualKey(vk, 0);
    
    		lParam = ScanCode << 16;
    		lParam |= 1;
    		
    		
    			PostMessage(WoW, WM_KEYDOWN, vk, lParam);
    			lParam |= 1 << 30;
    			lParam |= 1 << 31;
    			PostMessage(WoW, WM_KEYUP, vk, lParam);
    
    	}
    It works, but when the game window loses focus, it stops working.
    My bot is written as an injection dll.

    it is necessary to make it so that the bot can be run in several windows simultaneously.
    And for this, it must work without focus.

  4. #4
    reapler's Avatar Member
    Reputation
    7
    Join Date
    Jul 2014
    Posts
    6
    Thanks G/R
    2/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can try "005FBE10 CGInputControl__ToggleControlBit"
    Code:
    signed int __thiscall CGInputControl::ToggleControlBit(_DWORD *this, int flag, int enableFlag, int osAsyncTime, int a5)
    {
        _DWORD *v5; // esi
        signed int result; // eax
        int v7; // eax
    
        v5 = this;
        if ( enableFlag )
            result = CGInputControl::SetControlBit((int)this, flag, osAsyncTime);
        else
            result = CGInputControl::UnsetControlBit((int)this, flag, osAsyncTime, a5);
        if ( result )
        {
            if ( enableFlag )
            {
                if ( flag & 0x10F0 || flag & 3 && (v7 = v5[1], v7 & 1) && v7 & 2 )
                    CheckToCancelCurrentChannelSpell();
            }
            result = CInputControl::UpdatePlayer(v5, osAsyncTime, 1);
        }
        return result;
    }
    Code:
    enum eMovementFlag
    {
        MOVEMENT_FLAG_MOVE_FORWARD = 0x10,
        MOVEMENT_FLAG_MOVE_BACKWARD = 0x20,
        MOVEMENT_FLAG_STRAFE_LEFT = 0x40,
        MOVEMENT_FLAG_STRAFE_RIGHT = 0x80,
        MOVEMENT_FLAG_TURN_LEFT = 0x100,
        MOVEMENT_FLAG_TURN_RIGHT = 0x200,
        MOVEMENT_FLAG_PITCH_UP = 0x400,
        MOVEMENT_FLAG_PITCH_DOWN = 0x800,
        MOVEMENT_FLAG_AUTO_RUN = 0x1000,
        MOVEMENT_FLAG_ALL = 0x1FF0
    };
    Last edited by reapler; 11-04-2018 at 08:52 PM.

  5. #5
    Hrap's Avatar Active Member
    Reputation
    17
    Join Date
    Oct 2018
    Posts
    127
    Thanks G/R
    17/8
    Trade Feedback
    0 (0%)
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    CGInputControl::ToggleControlBit
    This function needs to be intercepted.
    Right?

  6. #6
    Hrap's Avatar Active Member
    Reputation
    17
    Join Date
    Oct 2018
    Posts
    127
    Thanks G/R
    17/8
    Trade Feedback
    0 (0%)
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Why does this function, as I understand it, switch control?

  7. #7
    Hrap's Avatar Active Member
    Reputation
    17
    Join Date
    Oct 2018
    Posts
    127
    Thanks G/R
    17/8
    Trade Feedback
    0 (0%)
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Your code is not yet understood
    Last edited by Hrap; 11-05-2018 at 11:15 AM.

  8. #8
    Hazzbazzy's Avatar wannabe hackerlol Authenticator enabled
    Reputation
    1346
    Join Date
    Aug 2011
    Posts
    1,215
    Thanks G/R
    256/489
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by Hrap View Post
    Hello,
    I ran into a keystroke emulation problem in WoW 3.3.5a.

    I first used WINAPI
    PostMessage
    but when the game window loses focus, pressing is no longer generated.
    I tried all possible WINAPI options, and no one works without focus

    I think I need something from WOW
    But how to implement it, I do not know yet


    I found the following
    00765AF0 OnKeyDown
    00764B90 OnKeyDownRepeat
    00763BE0 OnKeyUp

    as I understand, these events occur during keystrokes

    005FD3D0 InputControlDestroy_0
    005F9580 InputControlRegisterScriptFunctions
    00868D40 InputEvent
    CInputControl = 0x00C24954



    as I understand it, I need to use CInputControl or InputEvent
    Can you tell me how to implement keystroke emulation?
    At least in which direction to look.
    Thank you in advance
    Can you post the code you are using for this yourself?
    "HOLY TIME MACHINE BATMAN! it's 1973!"
    https://youtube.com/Hazzbazzy

  9. #9
    Hrap's Avatar Active Member
    Reputation
    17
    Join Date
    Oct 2018
    Posts
    127
    Thanks G/R
    17/8
    Trade Feedback
    0 (0%)
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I first tried to use it
    Code:
    	void GenerateKey(int vk, BOOL bExtended, BOOL Hold) {
    
    		LPARAM lParam;
    		int ScanCode = MapVirtualKey(vk, 0);
    
    		lParam = ScanCode << 16;
    		lParam |= 1;
    		if (Hold)
    		{
    			PostMessage(WoW, WM_KEYDOWN, vk, lParam);
    		}
    		else
    		{
    			lParam |= 1 << 30;
    			lParam |= 1 << 31;
    			PostMessage(WoW, WM_KEYUP, vk, lParam);
    		}
    		return;
    	}

    then

    Code:
    	void SetMove(int movetype,bool state)
    	{
    		if (movetype == MoveForward)
    		{
    			if (state)
    			{
    				reinterpret_cast<void(__cdecl*)(int)>(MoveForwardStart)(time);
    			}
    			else
    			{
    				reinterpret_cast<void(__cdecl*)(int)>(MoveForwardStop)(time);
    			}
    		}
    		if (movetype == MoveBackward)
    		{
    			if (state)
    			{
    				reinterpret_cast<void(__cdecl*)(int)>(MoveBackwardStart)(time);
    			}
    			else
    			{
    				reinterpret_cast<void(__cdecl*)(int)>(MoveBackwardStop)(time);
    			}
    		}
    		if (movetype == TurnLeft)
    		{
    			if (state)
    			{
    				reinterpret_cast<void(__cdecl*)(int)>(TurnLeftStart)(time);
    			}
    			else
    			{
    				reinterpret_cast<void(__cdecl*)(int)>(TurnLeftStop)(time);
    			}
    		}
    		if (movetype == TurnRight)
    		{
    			if (state)
    			{
    				reinterpret_cast<void(__cdecl*)(int)>(TurnRightStart)(time);
    			}
    			else
    			{
    				reinterpret_cast<void(__cdecl*)(int)>(TurnRightStop)(time);
    			}
    		}
    		if (movetype == JumpOrAscend)
    		{
    			if (state)
    			{
    				reinterpret_cast<void(__cdecl*)(int)>(JumpOrAscendStart)(time);
    			}
    			else
    			{
    				reinterpret_cast<void(__cdecl*)(int)>(AscendStop)(time);
    			}
    		}
    
    	}
    but without focus it doesn't work

    I haven't figured out CGInputControl yet
    I do not understand yet how it works



    I need to do so that the bot would work when the game window without focus
    please tell me how it can be implemented
    Last edited by Hrap; 11-05-2018 at 11:59 AM.

  10. #10
    Hazzbazzy's Avatar wannabe hackerlol Authenticator enabled
    Reputation
    1346
    Join Date
    Aug 2011
    Posts
    1,215
    Thanks G/R
    256/489
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by Hrap View Post
    I first tried to use it
    Code:
    	void GenerateKey(int vk, BOOL bExtended, BOOL Hold) {
    
    		LPARAM lParam;
    		int ScanCode = MapVirtualKey(vk, 0);
    
    		lParam = ScanCode << 16;
    		lParam |= 1;
    		if (Hold)
    		{
    			PostMessage(WoW, WM_KEYDOWN, vk, lParam);
    		}
    		else
    		{
    			lParam |= 1 << 30;
    			lParam |= 1 << 31;
    			PostMessage(WoW, WM_KEYUP, vk, lParam);
    		}
    		return;
    	}

    then

    Code:
    	void SetMove(int movetype,bool state)
    	{
    		if (movetype == MoveForward)
    		{
    			if (state)
    			{
    				reinterpret_cast<void(__cdecl*)(int)>(MoveForwardStart)(1000);
    			}
    			else
    			{
    				reinterpret_cast<void(__cdecl*)(int)>(MoveForwardStop)(1000);
    			}
    		}
    		if (movetype == MoveBackward)
    		{
    			if (state)
    			{
    				reinterpret_cast<void(__cdecl*)(int)>(MoveBackwardStart)(1000);
    			}
    			else
    			{
    				reinterpret_cast<void(__cdecl*)(int)>(MoveBackwardStop)(1000);
    			}
    		}
    		if (movetype == TurnLeft)
    		{
    			if (state)
    			{
    				reinterpret_cast<void(__cdecl*)(int)>(TurnLeftStart)(1000);
    			}
    			else
    			{
    				reinterpret_cast<void(__cdecl*)(int)>(TurnLeftStop)(1000);
    			}
    		}
    		if (movetype == TurnRight)
    		{
    			if (state)
    			{
    				reinterpret_cast<void(__cdecl*)(int)>(TurnRightStart)(1000);
    			}
    			else
    			{
    				reinterpret_cast<void(__cdecl*)(int)>(TurnRightStop)(1000);
    			}
    		}
    		if (movetype == JumpOrAscend)
    		{
    			if (state)
    			{
    				reinterpret_cast<void(__cdecl*)(int)>(JumpOrAscendStart)(1000);
    			}
    			else
    			{
    				reinterpret_cast<void(__cdecl*)(int)>(AscendStop)(1000);
    			}
    		}
    
    	}
    but without focus it doesn't work

    I haven't figured out CGInputControl yet
    I do not understand yet how it works
    What are you specifying "PostMessage(WoW" as?
    "HOLY TIME MACHINE BATMAN! it's 1973!"
    https://youtube.com/Hazzbazzy

  11. #11
    Hrap's Avatar Active Member
    Reputation
    17
    Join Date
    Oct 2018
    Posts
    127
    Thanks G/R
    17/8
    Trade Feedback
    0 (0%)
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    WoW is the game window HWND

    Code:
    HWND WoW;
    ...
    LRESULT CALLBACK WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
    {
    
    	if (uMsg == WM_USER_UNIQUE)
    
    	{
                // bot window is created here
    	return 0;		
    	}
    return CallWindowProc(OldWndProc, hwnd, uMsg, wParam, lParam);
    }
    
    
    extern "C" DLL_EXPORT BOOL APIENTRY DllMain(HMODULE Module, DWORD fdwReason, LPVOID lpvReserved)
    {
    	switch (fdwReason)
    	{
    	case DLL_PROCESS_ATTACH:
    
    		WoW = GetForegroundWindow();
    		if (WoW != NULL)
    		{
                       	WM_USER_UNIQUE = RegisterWindowMessage(TEXT("UI_WOWs_Launcher"));
    			OldWndProc = (WNDPROC)SetWindowLongPtr(WoW , GWLP_WNDPROC, (LONG_PTR)WndProc);
    			PostMessage(hw, WM_USER_UNIQUE, 0, 0);
    		}
    		
    		break;
    
    	}
    	
    	return TRUE; // successful
    };
    Last edited by Hrap; 11-05-2018 at 12:37 PM.

  12. #12
    Hazzbazzy's Avatar wannabe hackerlol Authenticator enabled
    Reputation
    1346
    Join Date
    Aug 2011
    Posts
    1,215
    Thanks G/R
    256/489
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by Hrap View Post
    Code:
    HWND WoW;
    ...
    extern "C" DLL_EXPORT BOOL APIENTRY DllMain(HMODULE Module, DWORD fdwReason, LPVOID lpvReserved)
    {
    	switch (fdwReason)
    	{
    	case DLL_PROCESS_ATTACH:
    
    		WoW = GetForegroundWindow();
    		if (WoW != NULL)
    		{
                         ....
    		}
    		
    		break;
    
    	case DLL_PROCESS_DETACH:
    		// detach from process
    		break;
    
    	case DLL_THREAD_ATTACH:
    		// attach to thread
    		break;
    
    	case DLL_THREAD_DETACH:
    		// detach from thread
    		break;
    	}
    	
    	return TRUE; // successful
    };
    If you want to isolate the problem, change your postmessage up slightly and use the PID to get the handle. See if the behavior is the same. If it's not then you know the above is the problem
    "HOLY TIME MACHINE BATMAN! it's 1973!"
    https://youtube.com/Hazzbazzy

  13. #13
    Hrap's Avatar Active Member
    Reputation
    17
    Join Date
    Oct 2018
    Posts
    127
    Thanks G/R
    17/8
    Trade Feedback
    0 (0%)
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    The behavior is the same.
    When I run the bot everything works great.
    but when i switch focus to another window the bot stops
    At the same time, messages continue to be sent but the game does not respond to them.
    Last edited by Hrap; 11-05-2018 at 03:56 PM.

  14. #14
    Hrap's Avatar Active Member
    Reputation
    17
    Join Date
    Oct 2018
    Posts
    127
    Thanks G/R
    17/8
    Trade Feedback
    0 (0%)
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I created a class for
    ToggleControlBit
    but I do not understand how to use it

    Code:
    class CGInputControl
    {  
    
    	typedef signed int(__cdecl* tSetControlBit)(int, int, int);
    	typedef signed int(__cdecl* tUnsetControlBit)(int, int, int ,int);
    	typedef signed int(__cdecl* tUpdatePlayer)(DWORD*, int, int);
    	typedef void(__cdecl* tCheckToCancelCurrentChannelSpell)();
    	tSetControlBit SetControlBit = (tSetControlBit)0x5fa170;
    	tUnsetControlBit UnsetControlBit = (tUnsetControlBit)0x5fa450;
    	tUpdatePlayer UpdatePlayer = (tUpdatePlayer)0x5FBBC0;
    	tCheckToCancelCurrentChannelSpell CheckToCancelCurrentChannelSpell = (tCheckToCancelCurrentChannelSpell)0x5FAA40;
    
    	signed int __thiscall ToggleControlBit(DWORD * This, int flag, int enableFlag, int osAsyncTime, int a5)
    	{
    		DWORD *v5; // esi
    		signed int result; // eax
    		int v7; // eax
    
    		v5 = This;
    		if (enableFlag)
    			result = SetControlBit((int)This, flag, osAsyncTime);
    		else
    			result = UnsetControlBit((int)This, flag, osAsyncTime, a5);
    		if (result)
    		{
    			if (enableFlag)
    			{
    				if (flag & 0x10F0 || flag & 3 && (v7 = v5[1], v7 & 1) && v7 & 2)
    					CheckToCancelCurrentChannelSpell();
    			}
    			result = UpdatePlayer(v5, osAsyncTime, 1);
    		}
    		return result;
    	}
    
    };

    I tried to do so

    Code:
    DetourFunction(reinterpret_cast<byte*>(0x5FBE10), reinterpret_cast<byte*>(CGInputControl::ToggleControlBit));

    and nothing happens



    as I understand it, I need to call ToggleControlBit and pass the flags I need
    Is it so?

  15. #15
    reapler's Avatar Member
    Reputation
    7
    Join Date
    Jul 2014
    Posts
    6
    Thanks G/R
    2/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by Hrap View Post
    as I understand it, I need to call ToggleControlBit and pass the flags I need
    Is it so?
    Yes, almost you also need to pass the CInputControl object & tickcount. The mentioned paste was more a example how the function itself look like. You may call it in the main thread via a delegate or asm/endscene.

    C# injected (c++? dunno):
    Code:
                [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
                internal delegate IntPtr CGInputControl_GetActiveDelegate();
                internal static CGInputControl_GetActiveDelegate CGInputControl_GetActive;
    
                [UnmanagedFunctionPointer(CallingConvention.ThisCall)]
                internal delegate int CGInputControl_ToggleControlBitDelegate(IntPtr activeCtrl, int type, int enable, int osAsyncTime, int unk0);
                internal static CGInputControl_ToggleControlBitDelegate CGInputControl_ToggleControlBit;
    
            public void MoveForward()
            {
                //delegates need to assigned before calling...
                Generic.MainThread.Instance.Invoke(() => 
                {
                    Functions.Client.CGInputControl_ToggleControlBit(Functions.Client.CGInputControl_GetActive(), 0x10, 1, System.Environment.TickCount, 0);
                }
            }
    or in asm
    Code:
                Memory.WowMemory.Inject(new[]
                {
                    "call " + (uint) 0x5F95D0,
                    "mov ecx, eax",
                    "call " + (KernelTickCountAddress),
                    "push 0",
                    "push eax",
                    "mov ebx, [" + enablePtr + "]",
                    "push ebx",//or push directly if pointer not needed
                    "mov ebp, [" + flagPtr + "]",
                    "push ebp",
                    "call " + (uint) 0x5FBE10,
                    "ret"
                }, out toggleControlBitBase, out toggleControlBitFunc);

Similar Threads

  1. WoW single player Emulator
    By squishface in forum World of Warcraft General
    Replies: 12
    Last Post: 01-31-2013, 02:05 PM
  2. ! QUESTIONS ASKED HERE :: The Emulator Specialists Answers Here. !
    By smithen1 in forum World of Warcraft Emulator Servers
    Replies: 2745
    Last Post: 01-30-2008, 10:08 AM
  3. Emulator server question
    By Durgoax in forum World of Warcraft General
    Replies: 0
    Last Post: 01-06-2007, 02:51 AM
  4. why cant you post in the wow emulation?
    By ShortButStrong in forum World of Warcraft General
    Replies: 0
    Last Post: 12-02-2006, 03:12 AM
  5. WowwoW Emulator - Help
    By Muryllis in forum World of Warcraft General
    Replies: 2
    Last Post: 06-24-2006, 08:12 PM
All times are GMT -5. The time now is 03:35 AM. Powered by vBulletin® Version 4.2.3
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Google Authenticator verification provided by Two-Factor Authentication (Free) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search