|
-
Dec 26th, 2004, 11:59 AM
#1
Thread Starter
Lively Member
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
-
Dec 26th, 2004, 12:23 PM
#2
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Dec 27th, 2004, 03:59 AM
#3
Thread Starter
Lively Member
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...
-
Dec 27th, 2004, 07:41 AM
#4
Fanatic Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|