开发者

How to send keystrokes to an application in C++

开发者 https://www.devze.com 2023-01-19 14:44 出处:网络
I\'m trying to make a program to open Acrobat files using Adobe Acrobat Reader and save them in a text file, automatically.

I'm trying to make a program to open Acrobat files using Adobe Acrobat Reader and save them in a text file, automatically. What I want my program to do is:

  • open the pdf
  • send Alt + Tab //to move to the acrobat tab
  • send Alt + F //to open file
  • send Down Down Down Down (4 times) //to select 'save as text' option
  • send Enter // to save

I'm using Windows OS. can someone please help me on how to do this?

Well my finel goal is to save the title and author of about 2500 pdf files in a开发者_如何学JAVA database automatically, what are the better ways you suggested ? this was what i came up with.


Try AutoIt. From it's website:

"AutoIt is a freeware Windows automation language. It can be used to script most simple Windows-based tasks."


You're going to want to use Spy++ and watch the messages being passed to the window when you perform these actions (note that opening the PDF with Acrobat and grabbing the Window handle are different operations). From there, look into:

http://msdn.microsoft.com/en-us/library/ms644950(VS.85).aspx

Win32 messaging is difficult if you're not used to it and fragile, as mentioned by @Alf. I'd suggest you try another approach, but if you Google "win32 sendmessage" or "win32 sendkeys" that should get you started.


Couple of things,

1) Simulating keystrokes to interact with another application is a very very bad idea. You're better off finding API's that'll do the same thing.

If you still haven't changed your mind, read further...

2) For Saving, Why not use Ctrl+S to save, Ctrl+O to open. I'm Sure you'll find direct shortcuts for the others too.

Here's a Project that might help.


You can use SendMessage API to send mouse and keyboard messages to a window, or you can use sendinput which simulates actual hardware events. I will agree with another person, use AutoIT

0

精彩评论

暂无评论...
验证码 换一张
取 消