TranslateMessage API , Help!


New member
Feb 1, 2017
Programming Experience
Hi there guys, im trying to simulate a key press with TranslateMessage but I dont know what parameters to pass to the object.

This is what I 've got so far:

        static extern bool TranslateMessage([In] ref MSG lpMsg);

        const int WM_KEYDOWN = 0x0100;
        const int WM_KEYUP = 0x0101;
        public struct MSG
            public IntPtr hwnd;
            public uint message;
            public IntPtr wParam;
            public IntPtr lParam;
            public uint time;
            public POINT pt;

        public struct POINT
            public int X;
            public int Y;

            public POINT(int x, int y)
                this.X = x;
                this.Y = y;

        static void Main(string[] args)
            MSG m = new MSG();
            m.message = 0x0D;
            //m.lParam = (IntPtr)WM_KEYDOWN;
            m.wParam = (IntPtr)WM_KEYDOWN;
   = new POINT();
            m.time = 0;
            bool p = TranslateMessage(ref m);

Im trying to send ENTER key or whatever..

Thanks im advance!
Cross posted over at Dream In Code.

As I said in your same topic over in DIC, TranslateMessage() isn't really going to help you much because that function only affects your own application. It won't send messages over to the other application that you are trying to control. To whit:
Translates virtual-key messages into character messages. The character messages are posted to the calling thread's message queue, to be read the next time the thread calls the GetMessage or PeekMessage function.
(emphasis mine)
What type of application are you making which requires API tampering? I ask aiming to possibly give you a better solution depending whether or not you can give some clarity on your project. I should also point out, asking for help with bots are generally frowned upon, unless they're being used in game development.
Top Bottom