Send key strokes to another application C#

2019-02-20 15:47发布

I need to automate FileMon.exe to startup with filters, save out the log it generates, and then exit.

My solution has been to write an assist application that will do all of this. Which has worked on starting up with specified filters and killing the process, but I still need it to save the log. Do you think it would be silly to send the application keystrokes to save the log? For instance I would send an Alt+F, Alt+S, type filepath, Enter.

How can you send keystrokes like above to another process that is running in C#?

标签: c# input
6条回答
狗以群分
2楼-- · 2019-02-20 16:15

Use something like AHK (Auto HotKey) it is a simple language that can be compiled to an EXE and is designed for automating the keyboard and mouse.

Also the IRC Channel and Forums always have people willing to help if need be.

查看更多
男人必须洒脱
3楼-- · 2019-02-20 16:23

You can use Windows.Forms.SendKeys to send keystrokes to the active application.

查看更多
爷、活的狠高调
4楼-- · 2019-02-20 16:23

You could use powershell and the windows automation cmdlets up on www.codeplex.com/wasp to do this.

-Oisin

查看更多
The star\"
5楼-- · 2019-02-20 16:30

That's probably a deaad end. You should look and see if the application (or one of its dependent DLLs) exposes the proper API calls to do what you are trying to do. If you had to do it by keystrokes, you could look into some kind of macro program like MacorMaker.

查看更多
Root(大扎)
6楼-- · 2019-02-20 16:32

Thanks for all the answers and help guys... I'm actually going to write and invoke a perl script using Win32::GuiTest.

查看更多
迷人小祖宗
7楼-- · 2019-02-20 16:38

As I know, you have to invoke some of native APIs:

-FindWindow to find parent windows you want to work with

-FindWindowEx to find true windows you'll send message to

-SendMessage to send key strokes to those windows

Details of these APIs, refer at MSDN :)

查看更多
登录 后发表回答