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++, help] PostMessage

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

Joined: 25 Jan 2009
Posts: 186

PostPosted: Sat Jun 19, 2010 8:12 pm    Post subject: [C++, help] PostMessage Reply with quote

I'm trying to send VK_TAB to a game, without it being active.

Code:

unsigned int scanCode = MapVirtualKey(VK_TAB, 0);
PostMessage(hWnd, WM_KEYDOWN, VK_TAB, scanCode << 16);
PostMessage(hWnd, WM_KEYUP, VK_TAB,   scanCode << 16);


From searching around the above code is how it's done.

The game receives the following events, from the above code: (Spy++)



And then when you actually press tab:



So I'm assuming that if cRepeat was set to 1 for WM_KEYDOWN, cRepeat/fRepeat/fUp set to 1 for WM_KEYUP, that it might work?

Also WM_CHAR seems to be sent twice, not sure if this has anything to do with it not working.
Back to top
View user's profile Send private message
Deltron Z
Expert Cheater
Reputation: 1

Joined: 14 Jun 2009
Posts: 164

PostPosted: Sun Jun 20, 2010 2:44 am    Post subject: Reply with quote

First of all, the first pictures shows WM_KEYDOWN->WM_KEYUP->WM_CHAR and in the second it's WM_KEYDOWN->WM_CHAR->WM_KEYUP.
Also, you might want to take a look at MSDN, haven't you wondered why you have to shift 16 bits left to the scan code? because the scan code is bits 16~23:
MSDN wrote:
lParam

The repeat count, scan code, extended-key flag, context code, previous key-state flag, and transition-state flag, as shown following.

Bits Meaning
0-15 The repeat count for the current message. The value is the number of times the keystroke is autorepeated as a result of the user holding down the key. If the keystroke is held long enough, multiple messages are sent. However, the repeat count is not cumulative.
16-23 The scan code. The value depends on the OEM.
24 Indicates whether the key is an extended key, such as the right-hand ALT and CTRL keys that appear on an enhanced 101- or 102-key keyboard. The value is 1 if it is an extended key; otherwise, it is 0.
25-28 Reserved; do not use.
29 The context code. The value is always 0 for a WM_KEYDOWN message.
30 The previous key state. The value is 1 if the key is down before the message is sent, or it is zero if the key is up.
31 The transition state. The value is always 0 for a WM_KEYDOWN message.

You can simply do:
Code:
(ScanCode << 16) | (RepeatTimes << 30)

Where repeat time is boolean (0 or 1) to set cRepeat.
Back to top
View user's profile Send private message
661089799107
Expert Cheater
Reputation: 3

Joined: 25 Jan 2009
Posts: 186

PostPosted: Sun Jun 20, 2010 2:07 pm    Post subject: Reply with quote



Thanks, this is what I have now: (It matches when tab is actually sent, but the game still isn't doing anything with it)

Code:

    // scanCode = 0x0F
    unsigned int scanCode = MapVirtualKey(VK_TAB, 0);

    // cRepeat = 1
    unsigned int keyDown = (1 << 0) | (scanCode << 16);

    // cRepeat = 1,  fRepeat = 1, fUp = 1
    unsigned int keyUp = (1 << 0) | (scanCode << 16) | (1 << 30) | (1 << 31);

    PostMessage(window, WM_KEYDOWN, VK_TAB, keyDown);
    PostMessage(window, WM_KEYUP, VK_TAB, keyUp);
Back to top
View user's profile Send private message
NoMercy
Master Cheater
Reputation: 1

Joined: 09 Feb 2009
Posts: 289

PostPosted: Sun Jun 20, 2010 4:06 pm    Post subject: Reply with quote

it could be hooked, use a tramplotine bypass
Back to top
View user's profile Send private message
661089799107
Expert Cheater
Reputation: 3

Joined: 25 Jan 2009
Posts: 186

PostPosted: Tue Jun 22, 2010 6:21 am    Post subject: Reply with quote

NoMercy wrote:
it could be hooked, use a tramplotine bypass


How can I tell if PostMessage is hooked? Would the PostMessageA function be changed in user32.dll? If so it doesn't seem to be any different when logged into the game.
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Tue Jun 22, 2010 7:44 pm    Post subject: Reply with quote

Depends on the type of hook.

If it's an IAT hook, you will need to check the IAT table of the application/module that you rerouted.

If it's a 'hook-hop' style hook, read the first chunk of the API and compare to what it should be.

There are plenty of other hooking methods, but those are the two most common to begin with.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1857

PostPosted: Tue Jun 22, 2010 7:52 pm    Post subject: Reply with quote

surely it's not hooked else the game wouldn't be receiving all those messages he's been trying to send anyway..
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Tue Jun 22, 2010 8:00 pm    Post subject: Reply with quote

Slugsnack wrote:
surely it's not hooked else the game wouldn't be receiving all those messages he's been trying to send anyway..


Just because the game is still receiving the messages doesn't mean it's not hooked. His messages could be passing through a hook.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1857

PostPosted: Tue Jun 22, 2010 8:06 pm    Post subject: Reply with quote

if that is the case, why would he care about whether there is a hook there or not lol ? that would be a poor, poor hook either way T_T
Back to top
View user's profile Send private message
Flyte
Peanuts!!!!
Reputation: 6

Joined: 19 Apr 2006
Posts: 1887
Location: Canada

PostPosted: Tue Jun 22, 2010 8:36 pm    Post subject: Reply with quote

The much more likely event is that the game uses DirectInput instead of windows messages.
Back to top
View user's profile Send private message
NoMercy
Master Cheater
Reputation: 1

Joined: 09 Feb 2009
Posts: 289

PostPosted: Wed Jun 23, 2010 1:33 am    Post subject: Reply with quote

Which game could be handy?
Back to top
View user's profile Send private message
661089799107
Expert Cheater
Reputation: 3

Joined: 25 Jan 2009
Posts: 186

PostPosted: Wed Jun 23, 2010 5:04 am    Post subject: Reply with quote

NoMercy wrote:
Which game could be handy?


Grand Fantasia


Last edited by 661089799107 on Mon Jun 28, 2010 7:41 pm; edited 2 times in total
Back to top
View user's profile Send private message
661089799107
Expert Cheater
Reputation: 3

Joined: 25 Jan 2009
Posts: 186

PostPosted: Mon Jun 28, 2010 7:39 pm    Post subject: Reply with quote

Flyte wrote:
The much more likely event is that the game uses DirectInput instead of windows messages.


I don't think it uses DirectInput(?) I couldn't find any calls for it. (DirectInput8Create, DirectInputCreateEx, etc)
Back to top
View user's profile Send private message
smartz993
I post too much
Reputation: 2

Joined: 20 Jun 2006
Posts: 2013
Location: USA

PostPosted: Mon Jun 28, 2010 8:19 pm    Post subject: Reply with quote

Bill87 wrote:
Flyte wrote:
The much more likely event is that the game uses DirectInput instead of windows messages.


I don't think it uses DirectInput(?) I couldn't find any calls for it. (DirectInput8Create, DirectInputCreateEx, etc)


Check GetProcAddress.
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