|
-
Jun 22nd, 2000, 11:23 PM
#1
Thread Starter
Frenzied Member
Does anyone know how to press enter in another program. I need this because I use lots of OCX's and some of them have a window that pops up when ever I load my program, and if you press enter, it closes the window. Please Help
NXSupport - Your one-stop source for computer help
-
Jun 22nd, 2000, 11:26 PM
#2
Thread Starter
Frenzied Member
NXSupport - Your one-stop source for computer help
-
Jun 23rd, 2000, 12:26 AM
#3
For sendkey, you do:
[/code]
Sendkeys "{Enter}"
or
Sendkeys "~"
[/code]
For api, try:
[/code]
Declare Function sendmessagebynum Lib "User" Alias "SendMessage" (ByVal hWnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Long) As Integer
Global Const WM_CHAR = &H102
Sub key_enter(ByVal hWnd As Integer)
X = sendmessagebynum(hWnd%, WM_CHAR, 13, 0)
End Sub
[/code]
-
Jun 23rd, 2000, 12:38 AM
#4
Fanatic Member
I recommend "SendMessage" over "SendKeys". Sendkeys is a unstable and not too reliable. It is use for more simple process.
Here is a sample of SendMessage, SendMessageByNum, and SendMessageString.
Code:
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function Findwindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function SendMessageByNum Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Const WM_LBUTTONDOWN = &H201
Private Const WM_LBUTTONUP = &H202
Private Declare Function SendMessageByString Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
Private Const WM_CLOSE = &H10
Sub p_Close_Dialog()
Dim lng_Dialog As Long
Dim lng_Button As Long
'PURPOSE: Get the handle of an application by the classname
lng_Dialog = Findwindow("#32770", vbNullString)
'lng_Dialog = Findwindow("XLMAIN", vbNullString)
'PURPOSE: Get extra information of that application
lng_Button = FindWindowEx(lng_Dialog, 0&, "Button", vbNullString)
'PURPOSE: Press the Buttons - Method #1
Call SendMessageByNum(lng_Button, WM_LBUTTONDOWN, 0, 0&)
Call SendMessageByNum(lng_Button, WM_LBUTTONUP, 0, 0&)
'PURPOSE: Press the Buttons - Method #2
Call SendMessage(lng_Button, WM_LBUTTONDOWN, 0, 0&)
Call SendMessage(lng_Button, WM_LBUTTONUP, 0, 0&)
'PURPOSE: Close the button
Call SendMessageByString(lng_Button, WM_CLOSE, 0, 0&)
'PURPOSE: Close the message box
Call SendMessageByString(lng_Dialog, WM_CLOSE, 0, 0&)
End Sub
If you want samples of "Sendkeys", hit F1 when you place your cursor on the word "Sendkeys". Keep in mind that "Sendkeys" is case sensitive. It is better to use capital letters.
Chemically Formulated As:
Dr. Nitro
-
Jun 23rd, 2000, 01:25 AM
#5
Thread Starter
Frenzied Member
how do I make the mouse click on the center of the screen?
NXSupport - Your one-stop source for computer help
-
Jun 23rd, 2000, 02:36 AM
#6
Use the SetCursorPos API to move it to the center and use the SendMessage API to click the button.
-
Jun 23rd, 2000, 02:39 AM
#7
Thread Starter
Frenzied Member
any code that does not include API? because I don't know how to use that
NXSupport - Your one-stop source for computer help
-
Jun 23rd, 2000, 06:28 AM
#8
It is pretty easy once you use it. Also you have to do is specify the X and Y coordinates for it.
Code:
Declare Function SetCursorPos Lib "user32" Alias "SetCursorPos" (ByVal x As Long, ByVal y As Long) As Long
' To use it, just specify an X and Y value for the cursor.
' Put the below code in a CommandButton.
Private Sub Command1_Click
SetCursorPos 100, 100
End Sub
-
Jun 23rd, 2000, 09:27 AM
#9
Thread Starter
Frenzied Member
NXSupport - Your one-stop source for computer help
-
Jun 23rd, 2000, 04:44 PM
#10
Fanatic Member
Megatron's example does work!
If you placed the codes in the form, then make sure you place the word "PRIVATE" infront of the API. Like this:
Code:
Private Declare Function SetCursorPos Lib "user32" Alias "SetCursorPos" (ByVal x As Long, ByVal y As Long) As Long
Drop a command button on the form and place these codes into the form too.
Code:
Private Sub Command1_Click
SetCursorPos 100, 100
End Sub
Chemically Formulated As:
Dr. Nitro
-
Jun 23rd, 2000, 09:20 PM
#11
That code moves the Mouse to (100,100). You can move it to the center of the screen by using some properties of the Screen object, for example, Width / 2 and Height / 2.
Then use the SendMessage to click the button. I believe the message is WM_LBUTTONDOWN.
-
Jun 23rd, 2000, 09:59 PM
#12
Thread Starter
Frenzied Member
Can someone please tell me what I did wrong, What happens is that it brings the mouse to the lower right corner of the screen:
Private Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
Private Sub Form_Load()
SetCursorPos Screen.Width / 2, Screen.Height / 2
End Sub
PS.... you know how you make the code look like how it looks in Visual Basic? how do you do that?
NXSupport - Your one-stop source for computer help
-
Jun 23rd, 2000, 11:32 PM
#13
Addicted Member
try this:
Code:
SetCursorPos (Screen.Width / 2) / Screen.TwipsPerPixelX, (Screen.Height / 2) / Screen.TwipsPerPixelY
because the screen.width and height gives you the width and height in twips, and setCursorPos deals with Pixels, so you have to conver Twips into Pixels, thats it.
and to show the code like vb see this link:
---> http://forums.vb-world.net/index.php?action=bbcode
-
Jun 24th, 2000, 12:07 AM
#14
Thread Starter
Frenzied Member
Now when it gets to the middle, how do I make it click?
NXSupport - Your one-stop source for computer help
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
|