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 


PostMessage LPARAM trouble

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

Joined: 21 Nov 2007
Posts: 14

PostPosted: Tue Dec 04, 2007 7:31 pm    Post subject: PostMessage LPARAM trouble Reply with quote

I'm working on a simple chat bot that just sends keystrokes via PostMessage(with the gg bypass). I've gotten the mouseclick to work, but i'm having trouble sending individual keystrokes:

Code:

void SendKey(char input) //or SendKey(short key) overloaded
{
   short key = VkKeyScan(input);
   UINT scancode = MapVirtualKey(key, 0);
   hhPostMessageA(lWnd, WM_KEYDOWN, key, scancode);
   Sleep(10);//just incase
   hhPostMessageA(lWnd, WM_CHAR, key, scancode);
   Sleep(10);//just incase
   hhPostMessageA(lWnd, WM_KEYUP, key, scancode);
}


Now the window gets the key, but my program crashes immediately after. I know it's something with my lparam because scancode is only giving me a uint when lparam is a DWORD. The winAPI shows the lparam with a list of parameters in its high-order word and low-order word. I get lost there >_>

how do i get a legitimate lparam?!
Back to top
View user's profile Send private message
appalsap
Moderator
Reputation: 0

Joined: 27 Apr 2006
Posts: 6753
Location: Pakistan

PostPosted: Tue Dec 04, 2007 7:34 pm    Post subject: Reply with quote

Set all the bits properly, it shows you on the PostMessage documentation.
If you don't know how, you need to learn more C.

_________________
Back to top
View user's profile Send private message
slippppppppp
Grandmaster Cheater
Reputation: 0

Joined: 08 Aug 2006
Posts: 929

PostPosted: Tue Dec 04, 2007 7:35 pm    Post subject: Reply with quote

void SendKey(char input)
{
short key = VkKeyScan(input);
UINT scancode = MapVirtualKey(key, 0);
hhPostMessageA(lWnd, WM_KEYDOWN, key, scancode);
Sleep(10);//just incase
hhPostMessageA(lWnd, WM_CHAR, key, scancode);
Sleep(10);//just incase
hhPostMessageA(lWnd, WM_KEYUP, key, scancode);
}


Im looking at your cold and these caught my attention:
lWnd, key, scancode.
These are declared in your procedure, but your proc:

void SendKey(char input)

doesnt include these. So try replacing that with:

Void SendKey(HWND lWnd, UINT message, WPARAM key, LPARAM scancode)
Back to top
View user's profile Send private message AIM Address MSN Messenger
fl00d
Newbie cheater
Reputation: 0

Joined: 21 Nov 2007
Posts: 14

PostPosted: Tue Dec 04, 2007 7:40 pm    Post subject: EDIT Reply with quote

I can now successfully run WM_KEYDOWN without my prorgam crashing, but the other 2 messages fail.

This is what I changed:
Code:

#define SETBITS(var,mask)   (var |= mask)
#define CLEARBITS(var,mask) (var &= ~mask)
#define CHKBITS(var,mask)   ((var&mask) == mask)

...

void SendKey(char input)
{
   LPARAM lParam;
   short key = VkKeyScan(input);
   UINT scancode = MapVirtualKey(key, 0);
   SETBITS(lParam,0x00021e00);
   hhPostMessageA(lWnd, WM_KEYDOWN, key, lParam);
   Sleep(10);
   SETBITS(lParam,0x00021e02);
   hhPostMessageA(lWnd, WM_CHAR, key, lParam);
   Sleep(10);
   SETBITS(lParam,0x00021e03);
   hhPostMessageA(lWnd, WM_KEYUP, key, lParam);
   Sleep(10);
}


I created 0x00021e0* from the documentation, but the last 2 params are failing-

Code:

29
    Specifies the context code. The value is 1 if the ALT key is held down while the key is pressed; otherwise, the value is 0.
30
    Specifies the previous key state. The value is 1 if the key is down before the message is sent, or it is 0 if the key is up.
31
    Specifies the transition state. The value is 1 if the key is being released, or it is 0 if the key is being pressed.


so, the first PostMessage() is obviously 0000. The second one that is not working is 0010, and the third is 0011.

Help?
Back to top
View user's profile Send private message
assaf84
Expert Cheater
Reputation: 0

Joined: 03 Oct 2006
Posts: 238

PostPosted: Wed Dec 05, 2007 1:16 am    Post subject: Reply with quote

Change this:
Code:
UINT scancode = MapVirtualKey(key, 0);

To this:
Code:
UINT scancode = (MapVirtualKey(key, 0) << 16) & 0x00FF0000 | 0x01000001;
Back to top
View user's profile Send private message
fl00d
Newbie cheater
Reputation: 0

Joined: 21 Nov 2007
Posts: 14

PostPosted: Wed Dec 05, 2007 9:07 pm    Post subject: Reply with quote

Found a solution. I guess lparam doesn't matter as much anyway, but it was a problem with one of my variables. i forgot to initialize scancode = 0x0; and setting that as the lparam works fine w/o crashing!

thanks again for all your help
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