I want to know which methods that allow you to do an action to a game while it's on the background.

I know there is sending packets in online games.

Is it possible to emulate a keypress to game in the background (without setforground) using PostMessage? or Injecting DLL

Or every action is possible to be activated by modifying values in the memory? (I tried this some things work some were very hard to find)

Or there is another way I haven't heard about?

Looking forward to hear your opinions

I have tried PostMessage but its not working for me.

My Code:

        public static extern UIntPtr FindWindow(string lpClassName, string lpWindowName);
        public static extern UIntPtr SendMessage(UIntPtr hWnd, uint Msg, UIntPtr wParam, UIntPtr lParam);
        public static extern UIntPtr PostMessage(UIntPtr hWnd, uint Msg, UIntPtr wParam, UIntPtr lParam);
        static void Main(string[] args)

        public static void sendKeystroke(ushort k)
            const uint WM_KEYDOWN = 0x0100;
            const uint WM_KEYUP = 0x0101;
            UIntPtr WindowToFind = FindWindow(null, "Warfare OnLine Client");
            UIntPtr result3 = PostMessage(WindowToFind, WM_KEYDOWN, ((UIntPtr)k), (UIntPtr)0b00000000000100010000000000000001);
            UIntPtr result4 = PostMessage(WindowToFind, WM_KEYUP, ((UIntPtr)k), (UIntPtr)0b11000000000100010000000000000001);
Let me know if there something I can change in my code to make PostMessage work or another method!