Hey Josh,
I saw that soon after posting and have since tried activating the
process on my own using the Shell command.
This keeps it in window form and allows me to get the process ID at
the same time.
I tried to come up with an algorithm which looks for any active
processes and kills them before I run the one I'm trying to control.
Anyhow - I soon understood that I need to insert the key to the system
input stream and not to an application input stream, even though it's
a hotkey.
That's because the application input stream is local to the
application and not global to the system like normal keystrokes are.
I'm trying to use the windows API like you suggested but I'm not sure
it'll work without first giving focus to that application again.
Will probably see if it works today.

Thanks anyhow and I would still like any input on how to activate a
hotkey in another process from mine.

Thank you,

Oren


On Jan 14, 4:11 pm, Josh wrote:
> 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, 
> likehttp://msdn.microsoft.com/en-us/library/ms646310.aspx.
>
> Josh
>
> On Jan 11, 6:10 am, Oren Kaplan 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