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 


[C#] Problem sending keys to process

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

Joined: 19 Apr 2007
Posts: 259
Location: Scandinavia

PostPosted: Tue Mar 25, 2008 5:07 am    Post subject: [C#] Problem sending keys to process Reply with quote

Hello there, i have a problem regarding sending keys to MapleStory, that i hope you can help me with.
A little information:
It is coded in C#
I use the SendMessage function to send keys to MapleStory
I send WM_KEYDOWN, WM_CHAR, and WM_KEYUP messages, in that order.

About what i want to happen in the sample code:
When the user presses button1, timer5 is activated
For every tick, the program searches for maplestory,
and when it finds it, the timer is disabled, and the handle is saved in childHandle.
Code:

//samplecode from OdeBot

private void button1_Click(object sender, EventArgs e)
        {
           timer5.Enabled = true;
        }
private void timer5_Tick(object sender, EventArgs e)
        {
            childHandle = Win32.FindWindow("MapleStoryClass", "");
           //got the class name from spy++
            if (childHandle == 0)
            {
                //Do nothing if Maplestory was not found
               
            }
            else
            {
               childAsString = childHandle.ToString();
               timer5.Enabled = false;
            }
        }


What happens is that the value of childHandle never changes,
meaning the program never finds the process.
Any response to this is appreciated. Thanks in advance.
Very Happy
Back to top
View user's profile Send private message MSN Messenger
Symbol
I'm a spammer
Reputation: 0

Joined: 18 Apr 2007
Posts: 5094
Location: Israel.

PostPosted: Tue Mar 25, 2008 5:13 am    Post subject: Reply with quote

Child window? this is the parent window.
If you play eMS, do FindWindow(NULL, "MapleStory") because the class for eMS isn't MapleStoryClass, and I think FindWindow is hooked now too.
Back to top
View user's profile Send private message
Odecey
Master Cheater
Reputation: 1

Joined: 19 Apr 2007
Posts: 259
Location: Scandinavia

PostPosted: Tue Mar 25, 2008 5:20 am    Post subject: Reply with quote

I know it`s the parent window, i just didnt change the variable name after
copying code from a notepad control i made. And this isnt for EMS, its for GMS.
I should perhaps have added that to the first post. Anyway, ill check if it has
to do with the class name.
Edit: I couldnt get it to find the GMS process, so i tried on EMS and it worked.
Only problem now is that when i try to send a message it throws an unhandled exception.
Edit2 : The exception was because there was some sort of error when passing on the handle value. MapleStory does not respond to the messages im sending though.
Edit: Does anyone know if you can even use SendMessage on MapleStory?
And if not, I would be happy to hear suggestions on what i can use instead.


Last edited by Odecey on Tue Mar 25, 2008 7:52 am; edited 1 time in total
Back to top
View user's profile Send private message MSN Messenger
Estx
Expert Cheater
Reputation: 0

Joined: 04 Mar 2008
Posts: 172

PostPosted: Tue Mar 25, 2008 7:50 am    Post subject: Reply with quote

For SendMessage, check out: http://pinvoke.net/default.aspx/user32/SendMessage.html

For getting the window handle; use an internal function. Easier to debug with amongst other things.
Code:
            System.Diagnostics.Process hProc = System.Diagnostics.Process.GetProcessesByName("maplestory")[0];
            IntPtr hWnd = hProc.MainWindowHandle;
            Form fMaple = System.Windows.Forms.Form.FromHandle(hWnd);
            fMaple.Focus();
(change 'maplestory' to whatever the executable file is called minus the extension).

Last edited by Estx on Tue Mar 25, 2008 8:06 am; edited 1 time in total
Back to top
View user's profile Send private message
Odecey
Master Cheater
Reputation: 1

Joined: 19 Apr 2007
Posts: 259
Location: Scandinavia

PostPosted: Tue Mar 25, 2008 8:04 am    Post subject: Reply with quote

Thanks Estx, Ill try using SendInput, but before i go through all the work
of changing the references, could you answer me on wether it works
on MapleStory or not? Regarding FindWindow vs GetProcessByName,
whats the diffrence?
Back to top
View user's profile Send private message MSN Messenger
Estx
Expert Cheater
Reputation: 0

Joined: 04 Mar 2008
Posts: 172

PostPosted: Tue Mar 25, 2008 8:28 am    Post subject: Reply with quote

GetProcessesByName() searches for all available processes of the specified string, the [0] after it selects the first found process. You can guarantee that you will find the main window handle using the code I wrote up above as long as the process is running. =)

Using FindWindow(), you need to use GetLastError() to debug if it's failing. The other downside about FindWindow() is that you will need to update your code should MapleStory's Window-title or Class-name change.

And sorry, I updated my post - I misread yours. I updated the link to goto the SendMessage() reference.
Back to top
View user's profile Send private message
Odecey
Master Cheater
Reputation: 1

Joined: 19 Apr 2007
Posts: 259
Location: Scandinavia

PostPosted: Tue Mar 25, 2008 8:41 am    Post subject: Mods, please remove the filtering of X****** :!: Reply with quote

http://forum.cheatengine.org/viewtopic.php?t=178609< ---
im not rewriting my post again just for this stupid filter to hinder me from posting it. this is the 7th time dammit. Ive added an attachment of my post instead.
Edit: Oh great, the txt format is blocked aswell. Im giving up here.
Back to top
View user's profile Send private message MSN Messenger
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