Results 1 to 14 of 14

Thread: ENTER

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2000
    Location
    East Providence, RI
    Posts
    1,715

    Question

    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

  2. #2

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2000
    Location
    East Providence, RI
    Posts
    1,715
    how do I do that?
    NXSupport - Your one-stop source for computer help

  3. #3
    Guest
    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]

  4. #4
    Fanatic Member
    Join Date
    Jan 2000
    Location
    Nitro
    Posts
    633
    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

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2000
    Location
    East Providence, RI
    Posts
    1,715
    how do I make the mouse click on the center of the screen?
    NXSupport - Your one-stop source for computer help

  6. #6
    Guest
    Use the SetCursorPos API to move it to the center and use the SendMessage API to click the button.

  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2000
    Location
    East Providence, RI
    Posts
    1,715
    any code that does not include API? because I don't know how to use that
    NXSupport - Your one-stop source for computer help

  8. #8
    Guest
    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

  9. #9

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2000
    Location
    East Providence, RI
    Posts
    1,715
    it didn't work
    NXSupport - Your one-stop source for computer help

  10. #10
    Fanatic Member
    Join Date
    Jan 2000
    Location
    Nitro
    Posts
    633

    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

  11. #11
    Guest
    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.

  12. #12

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2000
    Location
    East Providence, RI
    Posts
    1,715
    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

  13. #13
    Addicted Member Mih_Flyer's Avatar
    Join Date
    Mar 2000
    Location
    some place there
    Posts
    241
    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

  14. #14

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2000
    Location
    East Providence, RI
    Posts
    1,715
    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
  •  



Click Here to Expand Forum to Full Width