 |
 |

08-25-2004, 10:08 AM
|
|
Freshman
|
|
Join Date: Feb 2004
Posts: 46
|
|
Cursor positions and sending key strokes
|
I was wondering how I would go about getting a VB application to focus on a
specific window that is already running, and move the cursor to a preset position on that window and send a left mouse click and then some text via code.
Basically I want to take info from a vb form and have it automaticaly enter it into my company's old database interface by way of cusor position and send key strokes.
I have looked at using API's to do this but it looks very confusing to me. Is there an easier way to accomplish this.
Thanks for any help
|
|

08-25-2004, 10:49 AM
|
 |
Senior Contributor
Retired Leader * Expert *
|
|
Join Date: Nov 2003
Location: Buffalo, NY
Posts: 1,145
|
|
|
if you've already perused the APIs necessary, there really is no “easier way”. You may be able to get away with SENDKEYS, if your other application is completely keyboard enabled. Since you mention Cursor Position, I’m thinking this is not the case… API is the way to go.
...I've never been a fan of these "player piano" type applications. Typically there is a much better solution available if you only rethink your approach. Talk to the Db Directly, Generate Text Output that can be imported, something...
|
|

08-25-2004, 11:06 AM
|
|
Freshman
|
|
Join Date: Feb 2004
Posts: 46
|
|
|
I can't talk directly to the database. I'm just a user of it trying to make things easier for me. I'm not quite sure what API's to use.
|
|

08-26-2004, 10:01 AM
|
|
Freshman
|
|
Join Date: Feb 2004
Posts: 46
|
|
Please Help!
|
I have searched for and tried numerous examples of API functions found on this fourm. I tried Sendmessage, SendMessageByString, PostMessage and many more. Every time I tried all those other functions the window came into focus and nothing was entered at the current cursor position. I'm just a begginer with API's not sure what I am doing wrong.
All I want to do is take the caption of label2 of even text in a textbox and when I press my command button the text gets entered in the command line of this other program. It works with the following code just not all the time.
If anyone can give me any example code that would work with my situation would be greatly appreciated.
I have read many post that say sendkeys is not very reliable does anyone know why?
Private Sub Enter_Permit_btn_Click()
lHandle = FindWindow(vbNullString, "Session A - [24 x 80]")
'Set this window to the foreground
lHandle = SetForegroundWindow(lHandle)
SendKeys ("SM")
SendKeys (Label2)
SendKeys ("{ENTER}")
|
Last edited by jfisher88; 08-27-2004 at 07:24 AM.
Reason: No Response
|

08-28-2004, 11:40 AM
|
 |
Senior Contributor
Retired Leader * Expert *
|
|
Join Date: Nov 2003
Location: Buffalo, NY
Posts: 1,145
|
|
im not sure what to tell you. The problem with sendkeys is that it just keep's sending keys... if a msgbox pops up, or you alt-tab, sendkeys doesnt care... it will keep on sending your text, and wackyness can ensue...
regardless... this quick little test, works like a champ.
Code:
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
Private Sub cmd_Click()
Dim llHandle As Long
llHandle = FindWindow(vbNullString, "TextPad - [Document1]")
llHandle = SetForegroundWindow(llHandle)
DoEvents
SendKeys "This is a test"
SendKeys "%F S"
SendKeys "C:\MyTextText.txt"
SendKeys "{ENTER}"
End Sub
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|
|
|
 |
|