A quick scan of the MSDN documentation for AppActivate states that,
for the application you are targeting, "You can use AppActivate only
with processes that own windows."

You mentioned your process runs in the background in the system tray,
which leads me to believe there is no form present to be activated by
AppActivate.

Have you tried testing your code out against, say, the Windows
Calculator to see if that works (the sample code on MSDN for
My.Computer.Keyboard.SendKeys has an example of it, similar to yours)?

I haven't done much with sending my own input to other windows, but
you might be looking at having to do some Windows API stuff, like
http://msdn.microsoft.com/en-us/library/ms646310.aspx.

Josh

On Jan 11, 6:10 am, Oren Kaplan <[email protected]> wrote:
> Hello,
> I'm trying to send the "F9" key to windows as if it was typed on the
> keyboard.
> I'm using the following code:
>
>         Dim p As System.Diagnostics.Process
>         If
> System.Diagnostics.Process.GetProcessesByName("ShekelPC.exe").Count =
> 1 Then
>             For Each p In
> System.Diagnostics.Process.GetProcessesByName("ShekelPC.exe")
>                 AppActivate(p.Id)
>                 My.Computer.Keyboard.SendKeys("{F9}", True)
>             Next
>         End If
>         End
>
> After trying only:
>
>         My.Computer.Keyboard.SendKeys("{F9}", True)
>
> didn't help much.
>
> I'm trying to get "ShekelPC.exe" which sits in the background (in the
> system tray) to capture that "F9" keypress.
>
> It's like a hotkey for that application and I'm having a hard time
> managing to send that simple command to the system automatically
> instead of  physically pressing it.
>
> Why isn't my code working?
> If the key is sent as if pressed then the application should react as
> it normally does.
>
> Is there another, better way of doing this?
>
> Thanks
>
> Oren

Reply via email to