I am trying to control Windows Media Player from a seperate .NET
Application.
I am using Windows 32 API.
SendKeys is for Windows Forms but using this I cannot access a different
process.
Please let me know whether I am missing something here.
Well, SendKeys works by sending the key information to the _active_
application. This may or may not be your own. It's whichever application
is in the foreground with input focus. You definitely can use SendKeys
with a process other than your own.
I thought only Windows 32 API is the best way to access another process.
You'd still need the unmanaged API to bring the media player to the
foreground. It's just that SendKeys allows you to treat the key
information in a managed way.
If it's not appropriate for the media player to be the foreground, focused
application when you send the key data to it, then SendKeys isn't what you
want.
As for your original question: did you try those codes? Do they work as
you expect them to? If so, I'd say you got it right. If not, I'd say you
got it wrong.
I haven't bothered to figure out the codes myself, but IMHO the docs are
pretty clear on what should be sent. For WM_KEYDOWN and WM_KEYUP you'll
need to use the "VK" code for the P key in combination with the
appropriate code for the control key in order to generate the Control-P.
Note that by "in combination" I mean you need to generate the appropriate
messages for both keys.
I'm actually a bit surprised that there's no automation API for the
Windows Media Player. I'm assuming you've looked for such an API and was
unable to find it. If not, you might want to look into that as well. It
might be easier to be able to create a new WMP process instance from your
application that you can control directly rather than having to go through
the unmanaged API.
Sorry I don't know more about it. I was just trying to make sure you were
aware of the SendKeys class, in case that's something that was useful for
you.
Pete