TranslateMessage API , Help!

ginocapo

New member
Joined
Feb 1, 2017
Messages
2
Programming Experience
3-5
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:


C#:
[DllImport("user32.dll")]
        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;
        }

        [StructLayout(LayoutKind.Sequential)]
        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)
        {
            Thread.Sleep(3000);
            MSG m = new MSG();
            m.message = 0x0D;
            //m.lParam = (IntPtr)WM_KEYDOWN;
            m.wParam = (IntPtr)WM_KEYDOWN;
            m.pt = new POINT();
            m.time = 0;
            
            bool p = TranslateMessage(ref m);
        }
Im trying to send ENTER key or whatever..

Thanks im advance!
 

Sheepings

Senior Programmer
Joined
Sep 5, 2018
Messages
655
Location
UK
Programming Experience
10+

Skydiver

Well-known member
Joined
Apr 6, 2019
Messages
646
Location
Virginia Beach, VA
Programming Experience
10+
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)
 

Sheepings

Senior Programmer
Joined
Sep 5, 2018
Messages
655
Location
UK
Programming Experience
10+
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