C# - Sending messages to Google Chrome from C# application

后端 未结 4 711
北恋
北恋 2020-12-14 18:00

I\'ve been searching around, and I haven\'t found how I would do this from C#.

I was wanting to make it so I could tell Google Chrome to go Forward,

4条回答
  •  天命终不由人
    2020-12-14 18:50

    Ok, here's what I've got so far... I kinda know what I need to do, but it's just a matter of doing it now...

    Here's the window from Spy++, I locked onto the Chrome_RenderWidgetHostHWND and clicked the Back button on my keyboard. Here's what I got: alt text

    So here's my assumptions, and I've been playing with this forever now, I just can't figure out the values.

    IntPtr hWnd = FindWindow("Chrome_RenderWidgetHostHWND", null);
    SendMessage(hWnd, WM_KEYDOWN, VK_BROWSER_BACK, 0);
    SendMessage(hWnd, WM_KEYUP,   VK_BROWSER_BACK, 0);
    

    Now, I just don't know what I should make the WM_KEYDOWN/UP values or the VK_BROWSER_BACK/FORWARD values... I tried this:

    const int WM_KEYDOWN = 0x100;
    const int WM_KEYUP = 0x101;
    const int VK_BROWSER_BACK = 0x6A;
    const int VK_BROWSER_FORWARD = 0x69;
    

    The latter two values I got from the image I just showed, the ScanCodes for those two keys. I don't know if I did it right though. The former two values I got after searching google for the WM_KEYDOWN value, and someone used &H100 and &H101 for the two values. I've tried several other random ideas I've seen floating around. I just can't figure this out.

    Oh, and here's the SendMessage method

        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, uint lParam);
    

提交回复
热议问题