Results 1 to 4 of 4

Thread: sendkeys to active window

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2002
    Posts
    72

    sendkeys to active window

    Hi,
    Does anyone have any idea why this only work in design and not from the exe ?

    Option Explicit

    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long


    Public Sub RSPaste()
    Dim sClipboardData As String
    Dim iHwnd As Long

    sClipboardData = Clipboard.GetText()
    Clipboard.Clear
    If sClipboardData <> vbNullString Then
    Clipboard.SetText "wooo" & sClipboardData
    Else
    Clipboard.SetText "hoooo"
    End If
    iHwnd = FindWindowWild("*Visual Basic*", False)
    If iHwnd <> 0 Then
    SetForegroundWindow iHwnd
    SendKeys ("^v")
    End If

    End Sub

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: sendkeys to active window

    Because its not finding the window like on this line - iHwnd = FindWindowWild("*Visual Basic*", False).
    The function is not declared. Depending on how you have your error handling in VB it should be generating
    an error, but since it can not find the window it just sends the keys to the active window VB. Also,
    I dont think that the asterisks work as wild card chars. So it is actually looking for a window "*Visual Basic*"

    HTH
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Dec 2002
    Posts
    72

    Re: sendkeys to active window

    the FindWindowWild is declared in loacation, and it does find the proper window. but it still only works on VB and not by using the EXE...

  4. #4
    Fanatic Member
    Join Date
    Oct 2003
    Posts
    1,005

    Re: sendkeys to active window

    I noticed that you used Sendkeys ("^v")

    I use it this way...

    Sendkeys "^(v)"

    Maybe it's that.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width