Results 1 to 14 of 14

Thread: [RESOLVED] External App Not Accepting SendKeys

  1. #1

    Thread Starter
    Frenzied Member zynder's Avatar
    Join Date
    Nov 2006
    Location
    localhost
    Posts
    1,434

    Resolved [RESOLVED] External App Not Accepting SendKeys

    Hi guys,

    It's been a while since i touch VB6. Been trying to work on some sendkeys but i am stumped on this one.

    I am trying to send a text to a textbox. However, the app im trying to send keystrokes exits the moment i send the keys to its textbox. I am thinking it's detecting automated keystrokes and then exits. I tried to put delays and also resort to add the text to a clipboard and send keys ctrl+v but failed.

    Is there some sort of code wherein the app will detect the send keys as normal stroke just like typing using the keyboard?

  2. #2
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: External App Not Accepting SendKeys

    Are you by any chance using Vista/7? Those two have problems with SendKeys().

  3. #3

    Thread Starter
    Frenzied Member zynder's Avatar
    Join Date
    Nov 2006
    Location
    localhost
    Posts
    1,434

    Re: External App Not Accepting SendKeys

    No gavio. I am using Windows XP Pro SP3. The app im trying to connect is using Cisco VPN then connect to a secure site using Internet Explorer. Then upon opening one app, i want to send a username and password then click ok button.

    The sendkeys just wont work on that window. It will exit automatically.

    Here is a sample:
    vb Code:
    1. 'enter username
    2.     SendKeys "username", True
    3.     Sleep 1000
    4.     SendKeys "{TAB}", True
    5.     Sleep 1000
    6. 'enter password
    7.     SendKeys "password", True
    8.     Sleep 1000

    I tested it on different app and it worked but not on the app im talking about.

    Also tried this but failed.

    vb Code:
    1. Sleep 3000
    2.     Clipboard.Clear
    3.     Clipboard.SetText "username"
    4.     SendKeys "^{V}", True

  4. #4
    PowerPoster Fazi's Avatar
    Join Date
    Aug 2005
    Location
    Underworld
    Posts
    2,525

    Re: External App Not Accepting SendKeys

    zynder, what about a solution like this
    http://www.vbforums.com/showpost.php...78&postcount=2

  5. #5
    PowerPoster Fazi's Avatar
    Join Date
    Aug 2005
    Location
    Underworld
    Posts
    2,525

    Re: External App Not Accepting SendKeys

    or,

    an inet solution to access dynamic pages. you no lady, sendkeys are not reliable.

    Code:
    Private Sub Command1_Click()
    Inet1.Protocol = icHTTPS
    Inet1.Execute "https://xxxx/index.php", "POST", "username=xxx&password=xxxx", "Content-Type: application/x-www-form-urlencoded"
    
      While Inet1.StillExecuting
        DoEvents
      Wend
      
      Dim s$, ret$
      
      s = Inet1.GetChunk(1024)
      Do Until s = ""
        ret = ret & s
        s = Inet1.GetChunk(1024)
      Loop
      
      Me.TextBox1.Text = ret
    End Sub

  6. #6

    Thread Starter
    Frenzied Member zynder's Avatar
    Join Date
    Nov 2006
    Location
    localhost
    Posts
    1,434

    Re: External App Not Accepting SendKeys

    @Fazi

    I know sendkeys are not reliable but the app is not a totally a web based app. Ir actually runs an application with GUI. I also tried using Winspector ++ to get the handle of the app but the textbox has no handle. Winspector ++ detected the whole window as one so there's no way i can SETTEXT to it.

  7. #7

    Thread Starter
    Frenzied Member zynder's Avatar
    Join Date
    Nov 2006
    Location
    localhost
    Posts
    1,434

    Re: External App Not Accepting SendKeys

    How can i send text equivalent to a keyboard level?

  8. #8
    PowerPoster Fazi's Avatar
    Join Date
    Aug 2005
    Location
    Underworld
    Posts
    2,525

    Re: External App Not Accepting SendKeys

    Quote Originally Posted by zynder View Post
    How can i send text equivalent to a keyboard level?
    yah, keybd_event

    The keybd_event function synthesizes a keystroke. The system can use such a synthesized keystroke to generate a WM_KEYUP or WM_KEYDOWN message. The keyboard driver’s interrupt handler calls the keybd_event function.

    Code:
    Const VK_H = 72
    Const VK_E = 69
    Const VK_L = 76
    Const VK_O = 79
    Const KEYEVENTF_EXTENDEDKEY = &H1
    Const KEYEVENTF_KEYUP = &H2
    Private Declare Sub keybd_event Lib "user32.dll" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
    Private Sub Form_KeyPress(KeyAscii As Integer)
        'Print the key on the form
        Me.Print Chr$(KeyAscii);
    End Sub
    Private Sub Form_Paint()
        'KPD-Team 2000
        'URL: http://www.allapi.net/
        'E-Mail: [email protected]
        'Clear the form
        Me.Cls
        keybd_event VK_H, 0, 0, 0   ' press H
        keybd_event VK_H, 0, KEYEVENTF_KEYUP, 0   ' release H
        keybd_event VK_E, 0, 0, 0  ' press E
        keybd_event VK_E, 0, KEYEVENTF_KEYUP, 0  ' release E
        keybd_event VK_L, 0, 0, 0  ' press L
        keybd_event VK_L, 0, KEYEVENTF_KEYUP, 0  ' release L
        keybd_event VK_L, 0, 0, 0  ' press L
        keybd_event VK_L, 0, KEYEVENTF_KEYUP, 0  ' release L
        keybd_event VK_O, 0, 0, 0  ' press O
        keybd_event VK_O, 0, KEYEVENTF_KEYUP, 0  ' release O
    End Sub

  9. #9
    PowerPoster Fazi's Avatar
    Join Date
    Aug 2005
    Location
    Underworld
    Posts
    2,525

    Re: External App Not Accepting SendKeys

    Quote Originally Posted by zynder View Post
    @Fazi

    I know sendkeys are not reliable but the app is not a totally a web based app. Ir actually runs an application with GUI. I also tried using Winspector ++ to get the handle of the app but the textbox has no handle. Winspector ++ detected the whole window as one so there's no way i can SETTEXT to it.
    is this a webpased app? still i did not get the idea. phaps a screen shot of that would be

  10. #10

    Thread Starter
    Frenzied Member zynder's Avatar
    Join Date
    Nov 2006
    Location
    localhost
    Posts
    1,434

    Re: External App Not Accepting SendKeys

    Thanks. I'll give this a shot. I will keep you posted.

  11. #11

    Thread Starter
    Frenzied Member zynder's Avatar
    Join Date
    Nov 2006
    Location
    localhost
    Posts
    1,434

    Re: External App Not Accepting SendKeys

    @Fazi

    Very nice the keyboard event seems to do the job. At any rate, do you have the list of CONST for numbers 0-9?

  12. #12
    PowerPoster Fazi's Avatar
    Join Date
    Aug 2005
    Location
    Underworld
    Posts
    2,525

    Re: [RESOLVED] External App Not Accepting SendKeys


  13. #13

    Thread Starter
    Frenzied Member zynder's Avatar
    Join Date
    Nov 2006
    Location
    localhost
    Posts
    1,434

    Re: [RESOLVED] External App Not Accepting SendKeys

    Yeah thanks for that I got the 0-9 and letters part but the TAB part isn't working. I guess i ran out of options.

    I tried the TAB keyboard event to notepad and the TAB was a success however not on the app i am having problems with. The letters and numbers did fine but not TAB.

  14. #14
    PowerPoster Fazi's Avatar
    Join Date
    Aug 2005
    Location
    Underworld
    Posts
    2,525

    Re: [RESOLVED] External App Not Accepting SendKeys

    Quote Originally Posted by zynder View Post
    Yeah thanks for that I got the 0-9 and letters part but the TAB part isn't working. I guess i ran out of options.

    I tried the TAB keyboard event to notepad and the TAB was a success however not on the app i am having problems with. The letters and numbers did fine but not TAB.
    oh

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