Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. AppActivate and Send Keys not working correctly

AppActivate and Send Keys not working correctly

Scheduled Pinned Locked Moved Visual Basic
csharpdatabasevisual-studiolinuxsecurity
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    CARisk3
    wrote on last edited by
    #1

    Okay, I am trying to automate the download of data from a web based database. I can automate the login in and getting to the right pages, but when I try to download the database I get a "File Download - Security Warning" popup message box. I have tried to use AppActivate to put the focus on the message box and then send the keys to click the save button on the popup message box. This doesn't work correctly. The AppActivate seems to activate the message box, but when I send the keys it sends to the visual studio menus. Could someone point me in the direction of an article or explain to me how to make this work correctly? I have used Goggle (where I got the code I am using) but I can't find anything that says different than what I am doing. I am not using this on a windows form it is an aspx page. (Sample code that I am using) Dim objShell objShell = CreateObject("WScript.Shell") AppActivate("File Download - Security Warning") objShell.SendKeys.Send("%S") objShell.SendKeys.Send("{Enter}") Thanks in advance for any assistance with this problem.

    If you can’t have fun at work, then why go to work?

    D 1 Reply Last reply
    0
    • C CARisk3

      Okay, I am trying to automate the download of data from a web based database. I can automate the login in and getting to the right pages, but when I try to download the database I get a "File Download - Security Warning" popup message box. I have tried to use AppActivate to put the focus on the message box and then send the keys to click the save button on the popup message box. This doesn't work correctly. The AppActivate seems to activate the message box, but when I send the keys it sends to the visual studio menus. Could someone point me in the direction of an article or explain to me how to make this work correctly? I have used Goggle (where I got the code I am using) but I can't find anything that says different than what I am doing. I am not using this on a windows form it is an aspx page. (Sample code that I am using) Dim objShell objShell = CreateObject("WScript.Shell") AppActivate("File Download - Security Warning") objShell.SendKeys.Send("%S") objShell.SendKeys.Send("{Enter}") Thanks in advance for any assistance with this problem.

      If you can’t have fun at work, then why go to work?

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      SendKeys is notoriously unreliable. Since Windows is a shared envrionment, the focus can move from one control or window to another at any time and for any reason. The focus can move between the AppActivate statement and your call to SendKeys. You'll have to use a more reliable method that sends key strokes directly to a window's message pump instead. You'll use the Win32 API functions FindWindow and SendMessage at the very least.

      A guide to posting questions on CodeProject[^]
      Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
           2006, 2007, 2008

      C 2 Replies Last reply
      0
      • D Dave Kreskowiak

        SendKeys is notoriously unreliable. Since Windows is a shared envrionment, the focus can move from one control or window to another at any time and for any reason. The focus can move between the AppActivate statement and your call to SendKeys. You'll have to use a more reliable method that sends key strokes directly to a window's message pump instead. You'll use the Win32 API functions FindWindow and SendMessage at the very least.

        A guide to posting questions on CodeProject[^]
        Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
             2006, 2007, 2008

        C Offline
        C Offline
        CARisk3
        wrote on last edited by
        #3

        Do you know of a good website or article that explains how to do this? I have been working on this about a week and it is the hold up of me finishing this project. I will try googling it, but if you know of a good resource that would be appreciated. Thanks

        If you can’t have fun at work, then why go to work?

        1 Reply Last reply
        0
        • D Dave Kreskowiak

          SendKeys is notoriously unreliable. Since Windows is a shared envrionment, the focus can move from one control or window to another at any time and for any reason. The focus can move between the AppActivate statement and your call to SendKeys. You'll have to use a more reliable method that sends key strokes directly to a window's message pump instead. You'll use the Win32 API functions FindWindow and SendMessage at the very least.

          A guide to posting questions on CodeProject[^]
          Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
               2006, 2007, 2008

          C Offline
          C Offline
          CARisk3
          wrote on last edited by
          #4

          Thanks for the information. I found some code but I'm not quite understanding it. Below is the snippet I am using:

          Dim docName = FindWindow(vbNullString, "File Download - Security Warning")

          Const BM_CLICK As Integer = &H102

          SendMessage(docName, BM_CLICK, 0, 0)

          I have the following two questions: What does the &H102 stand for? And where or how do I tell it that I want the saved button clicked? The save button does have the short cut key of Alt-S that I can send, but I don't understand where that information goes. Thank you for any assistance with this issue.

          If you can’t have fun at work, then why go to work?

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups