Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
478 views
in Technique[技术] by (71.8m points)

c# - Sending right ALT+C with PostMessage

I trying to send in my application RIGHT ALT + C.

I tried do it following:

PostMessage(hWindow, WM_KEYDOWN, (IntPtr)0x0043, (IntPtr)0x0012);
Delay(1000);
PostMessage(hWindow, WM_KEYUP, (IntPtr)0x0043, (IntPtr)0x0012);

and

PostMessage(hWindow, WM_KEYDOWN, (IntPtr)0x0043, (IntPtr)0x0001);
Delay(1000);
PostMessage(hWindow, WM_KEYUP, (IntPtr)0x0043, (IntPtr)0x0001);

but it doesn't correctly. How should I used it?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Yes, it's possible using PostMessage. I used program Spy++ (it's inside Visual Studio or you can download it http://mdb-blog.blogspot.com/2010/11/microsoft-spy-or-spyxx-for-download.html) I runed notepad.exe and Spy++, and used Function FindWindow to handle this notepad. Then I used Spy->LogMessages, in Tab Messages I cleared all and stay checkbox Keyboard and in output I checked Raw Message Parameters.

Then in notepad i pressed alt+1 and I noted values from Window Messages. I known now, where use WM_KEYDOWN, WM_KEYUP, WM_SYSKEYUP etc. and value lParam, wParam.

My function:

    public void PressKeyWithAlt(uint key, uint lParamDown, uint lParamUp)
    {
        PostMessage(hWindow, WM_KEYDOWN, VK_CONTROL, 0x001D0001);
        PostMessage(hWindow, WM_KEYDOWN, VK_MENU, 0x21380001);
        PostMessage(hWindow, WM_KEYDOWN, key, lParamDown);
        Delay(1000);
        PostMessage(hWindow, WM_KEYUP, key, lParamUp);
        PostMessage(hWindow, WM_SYSKEYUP, VK_CONTROL, 0xE01D0001);
        PostMessage(hWindow, WM_KEYUP, VK_MENU, 0xC1380001);
    }

and for example for alt+1

PressKeyWithAlt(VK_1, 0x20020001, 0xE0020001);

Thank you for all help.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...