Home All Groups Group Topic Archive Search About

SendKeys to another app don't work intentionally

Author
6 Oct 2006 10:24 AM
Morten Snedker
I have this piece of code that sets focus to the the windows
calculator application (calc.exe). Efter focus I try simply to pass
the number 5 to the application.

The calculater gets focus and is shown, but the number 5 is not
displayed. Have I missed something?

Sub SetWindowFocus()

        Dim hwndApp As IntPtr
        Dim hwndForeground As IntPtr
        Dim ThreadForeground As Integer

        hwndApp = FindWindow(vbNullString, "Lommeregner")
        If Not hwndApp.Equals(IntPtr.Zero) AndAlso _
            Not hwndApp.Equals(GetForegroundWindow) Then
            ThreadForeground =
GetWindowThreadProcessId(hwndForeground, IntPtr.Zero)
            AttachThreadInput(ThreadForeground, 0, True)
            SetForegroundWindow(hwndApp)
            AttachThreadInput(ThreadForeground, 0, False)
        End If

        SendKeys.SendWait("5")
        'SendKeys.Send("5")

End Sub

Regards /Snedker

Author
6 Oct 2006 10:42 AM
Morten Snedker
On Fri, 06 Oct 2006 12:24:27 +0200, Morten Snedker
<morten_spammenot_ATdbconsult.dk> wrote:

I put the sendkeys on a timer with 1sec delay. This seems to help.
Furthermore I need to use SendWait to make it work.

/Snedker
Author
7 Oct 2006 2:23 AM
Dylan Copeland
Sir, you try sending the actual number 5 key instead of the text, "5".