Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


how can I Sendkeys to an inactive window in C#[Fixed]

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
vnlagrla
Cheater
Reputation: 0

Joined: 10 Apr 2011
Posts: 33

PostPosted: Tue Feb 07, 2012 12:08 pm    Post subject: how can I Sendkeys to an inactive window in C#[Fixed] Reply with quote

I'm trying to do it using PostMessage or SendMessage but It just doesn't seem to work. does anyone know of a tut for this or have any helpful links?

Last edited by vnlagrla on Tue Feb 07, 2012 3:39 pm; edited 1 time in total
Back to top
View user's profile Send private message
Cryoma
Member of the Year
Reputation: 198

Joined: 14 Jan 2009
Posts: 1819

PostPosted: Tue Feb 07, 2012 12:42 pm    Post subject: Reply with quote

Are you targeting that window specifically or just targeting the foremost window?
Back to top
View user's profile Send private message
vnlagrla
Cheater
Reputation: 0

Joined: 10 Apr 2011
Posts: 33

PostPosted: Tue Feb 07, 2012 3:39 pm    Post subject: Reply with quote

I am Targeting a specific window. After searching google over free Period and lunch. I got it to work by converting a VB source to C# and here is how it looks

Win32
Code:
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace sendkey
{
    public static class Win32
    {

        public const int WM_SETCURSOR = 0x020;
        public const int WM_COMMAND = 0x111;
        public const int WM_KEYDOWN = 0x100;
        public const int WM_KEYUP = 0x101;
        public const int WM_CHAR = 0x102;
        public const int WM_MOUSEMOVE = 0x200;
        public const int WM_LBUTTONDOWN = 0x201;
        public const int WM_LBUTTONUP = 0x202;
        public const int WM_LBUTTONDBLCLK = 0x203;

        public const int GWL_EXSTYLE = -20;
        public const int WS_EX_TOOLWINDOW = 0x00000080;
        public const int WS_EX_APPWINDOW = 0x00040000;
        public const int  WM_SETTEXT = 0x0C;

        [DllImport("User32.dll")]
        public static extern IntPtr FindWindow(string strClassName, string strWindowName);


        [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
        public static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr childAfter, string lclassName, string windowTitle);


        [DllImport("User32.dll")]
        public static extern IntPtr SendMessage(IntPtr hWnd, IntPtr Msg, IntPtr wParam, string lParam);
    }
}


Main
Code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace sendkey
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        public void Sendkey()
        {
           
            IntPtr notepadHwnd = Win32.FindWindow(null, "Untitled - Notepad");

            IntPtr editHwnd = Win32.FindWindowEx(notepadHwnd, (IntPtr)0, "Edit", null);

            Win32.SendMessage(editHwnd, (IntPtr)Win32.WM_SETTEXT,(IntPtr) 0, "programatically added text!");
        }
        private void button1_Click(object sender, EventArgs e)
        {
              Sendkey();
        }
    }
}
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites