Fellow botters, what am I doing wrong here?

jamie3000

Elite Member
Executive VIP
Jr. VIP
Joined
Jun 30, 2014
Messages
13,739
Reaction score
5,216
I'm using PostMessage to send keys to third party software.. This code below works fine for Uppercase characters but when I send Lowercase it seems to send 3 of each character sent.

This is a cut down example of sending the "c" character. I know its not the software because it does the same in notepad.

What am i doing wrong here?

[DllImport("user32.dll")]
[return:MarshalAs(UnmanagedType.Bool)]
staticextern bool PostMessage(IntPtr hWnd,uint msg,IntPtr wParam,IntPtr lParam);

constint WM_KEYDOWN =0x100;
constint WM_KEYUP =0x101;
constInt32 WM_CHAR =0x0102;

IntPtr val =newIntPtr((Int32)'c');
PostMessage(WindowHandle, WM_KEYDOWN, (IntPtr)(val -0x020),newIntPtr(0));
PostMessage(WindowHandle, WM_CHAR, (IntPtr)val,newIntPtr(0));
PostMessage(WindowHandle, WM_KEYUP, (IntPtr)(val -0x020),newIntPtr(0));
 
just use autoit if this is all you're wanting. much less code. use the help file in the editor.
 
just use autoit if this is all you're wanting. much less code. use the help file in the editor.

Ye i did look at that, you can get a lib for c# as well but I wanted to keep it all native. Still though, another option if I can't figure this out :-)
 
Spy++ output is

<000001> 000204B6 P WM_KEYDOWN nVirtKey:'C' cRepeat:1 ScanCode:2E fExtended:0 fAltDown:0 fRepeat:0 fUp:0
<000002> 000204B6 P WM_CHAR chCharCode:'99' (99) cRepeat:1 ScanCode:2E fExtended:0 fAltDown:0 fRepeat:0 fUp:0
<000003> 000204B6 P WM_KEYUP nVirtKey:'C' cRepeat:1 ScanCode:2E fExtended:0 fAltDown:0 fRepeat:1 fUp:1
 
Back
Top