Windows Vista Beta | WinVistaBeta.com - Message | A reliable SENDKEYS for vb 2005 using Windows API

July 05, 2008  
Subject: A reliable SENDKEYS for vb 2005 using Windows API
Group: microsoft.public.windows.developer.winfx.general
Date: 1/10/2008 6:41:01 AM
From: =?Utf-8?B?U3RldmU=?= [Email Address Protection]




Can someone help me please

I am disabled and have been working for sometime on an application
that will help me interface with my PC better. it involves sending text
and commands to third party applications .I have tried appactivate and
sendkeys but find this to be unreliable. The best I have come up with
so far is

Public Class Form2
'Get a handle to an application window.
Declare Auto Function FindWindow Lib "USER32.DLL" ( _
ByVal lpClassName As String, _
ByVal lpWindowName As String) As IntPtr

'=====needed for 'set to foreground and show =====

Public Const SW_RESTORE As Integer = 9

Public Declare Function ShowWindow Lib "user32.dll" (ByVal hwnd As
Integer, ByVal nCmdShow As Integer) As Integer

' Activate an application window.
Declare Auto Function SetForegroundWindow Lib "USER32.DLL" _
(ByVal hWnd As IntPtr) As Boolean


Dim target_title As String = "Untitled - Notepad"
Dim send_keys_count As Int16 = 0

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click

Dim target_handle As IntPtr = FindWindow(Nothing, target_title)

'set to foreground and show
SetForegroundWindow(target_handle)
ShowWindow(target_handle, SW_RESTORE)

'=== I need to replace the next three lines
For n As Int64 = 1 To 5000000 'DELAY IS ESSENTIAL
Next
SendKeys.SendWait("Hello")
'=== replacemet ends


End Sub

End Class


This works fine for applications like notepad and word but gives
unreliable results in internet explorer (ie7), Google search page at least,
it sends multiple characters at times.

I would like to do away with sendkeys altogether, especially as vista
does not support it. Information on the web seems to suggest that the
sendinput api is probably the api to use or possibly sendmessage.
Could someone please show me exactly how to replace the lines indicated
above, along with any imports or declarations etc. as I am new to both
windows api and vb.net.

Alternatively a way of sending paste (and perhaps copy) to internet
explorer (ie7) would help.

Sendkeys(“^v”)

and variations doesn’t work in the code above



Many thanks

Steve


Back