1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Fellow botters, what am I doing wrong here?

Discussion in 'Programming' started by jamie3000, Jun 19, 2016.

  1. jamie3000

    jamie3000 Supreme Member

    Joined:
    Jun 30, 2014
    Messages:
    1,311
    Likes Received:
    587
    Occupation:
    Finance coder looking for semi-retirement
    Location:
    uk
    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));
     
  2. The Doctor

    The Doctor Jr. VIP Jr. VIP

    Joined:
    Dec 18, 2010
    Messages:
    888
    Likes Received:
    261
    Occupation:
    Computer Scientist, Engineer, Programmer.
    Location:
    ☆☆☆☆☆☆
    Home Page:
    just use autoit if this is all you're wanting. much less code. use the help file in the editor.
     
  3. jamie3000

    jamie3000 Supreme Member

    Joined:
    Jun 30, 2014
    Messages:
    1,311
    Likes Received:
    587
    Occupation:
    Finance coder looking for semi-retirement
    Location:
    uk
    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 :)
     
  4. jamie3000

    jamie3000 Supreme Member

    Joined:
    Jun 30, 2014
    Messages:
    1,311
    Likes Received:
    587
    Occupation:
    Finance coder looking for semi-retirement
    Location:
    uk
    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
     
  5. psychognost

    psychognost Newbie

    Joined:
    Apr 4, 2013
    Messages:
    3
    Likes Received:
    0
    Did you figure out what you are doing wrong?