locked
Sendkeys oddity RRS feed

  • Question

  • I am using visual basic code, specifically the sendkeys.send method, to send keystrokes to  a different application,  in my case Acrobat Reader.  Here is my problem.  I am sending instructions and text to define a path to a file I want to open in Acrobat Reader.  Every keystroke is being sent and interpreted in Reader correctly except the Colon.  This is the line of code I am using:

    Sendkeys.send("C:\")

    I have tried every variation of this simple line of code I can think of, but the result is the same.  Reader for some reason wants to interpret the Colon as Uppercase Q, so what I get is CQ\.  This of course totally messes up my path to the file I want to open.

    Sendkeys. sendwait("C:\")  Behaves the same

    I understand there are timing issus with this method so I have added code to my app.config file suggested in this forum for taking care of the timing issue.  I have also inserted delays into the execution of the program steps.  Nothing I have done solves this problem.

    I wonder if anyone else has experienced this or a similar problem and if so what was done to correct it.

    Sunday, July 26, 2009 5:44 PM

Answers

  • Why not use Process to open your file?  Here's how, and it's very simple:

        Dim p As New ProcessStartInfo
        p.FileName = "acrobat.exe"
        p.Arguments = (" C:\2009-06-15.pdf")
        Process.Start(p)
    

    This code opens the PDF file in a new process.  You can use as many Arguments as you need (or that are allowed by Acrobat).  The string literal in the Arguments line above can also be a variable that contains the path and filename of the PDF you want to open.


    Doug

    SEARCH ... then ask
    Monday, July 27, 2009 2:46 AM

All replies

  • This behaved better:

        AppActivate("Adobe Reader")
        My.Computer.Keyboard.SendKeys("^o")
        My.Computer.Keyboard.SendKeys("C:\Temp\Test.pdf")
        My.Computer.Keyboard.SendKeys("{TAB}{TAB}{ENTER}")
    

    SendKeys is never going to be very reliable, but I've found the most reliable SendKeys to be the Windows Script Host SendKeys.  I use it for logging into web sites (particularly this one) and it is very reliable in this application.

    Sunday, July 26, 2009 8:54 PM
  • Thanks John, but this also did not work.  I tried this approach ealier and found it to be extremely unreliable.  If sendkeys is so unreliable why even offer it in Visual basic?  Every character got sent properly except the Colon ":".  Again it came across as an Uppercase Q.  I have another question before I invest a lot of time in learning about Windows Scripting.  Can one of these scripts be run programatically from within a basic Program?  If so can you point me to some examples.  The only thing I have seen so far is that these can be run from a command line.
    Sunday, July 26, 2009 10:49 PM
  • Reference Windows Script Host on the Com tab.

    What happened when you used the code I posted?

    Sunday, July 26, 2009 10:53 PM
  • Exactly what happened before

    Colon came across as Uppercase Q.  Everything else came across as it should.

    This is what I got  === >     CQ\Temp\Test.pdf
    Monday, July 27, 2009 12:06 AM
  • Probably not a SendKeys problem.  Use a recorder to write a macro and see if you get the same result.
    Monday, July 27, 2009 12:45 AM
  • I dont know how to do what you ask and I really dont want to know.  I can tell you that I dimensioned a string variable Colon and defined it as ":"

    Colon = ":"
    msgbox(Colon)
    My.Computer.Keyboard.SendKeys(Colon)


    The msgbox(Colon) yields ":"
    The sendkeys yields "Q" In Acrobat reader

    It would also appear that the problem exists for "<"   sendkeys yields \   while ">"  sendkeys yields |.  Conversely  msgbox yields < and > respectively.

    If you have any insights as to what might be causing this problem besides sendkeys I would appreciate any advise. Thanks.
    Monday, July 27, 2009 1:18 AM
  • I dont know how to do what you ask and I really dont want to know. 

    Don't use SendKeys.
    Monday, July 27, 2009 1:53 AM
  • Why not use Process to open your file?  Here's how, and it's very simple:

        Dim p As New ProcessStartInfo
        p.FileName = "acrobat.exe"
        p.Arguments = (" C:\2009-06-15.pdf")
        Process.Start(p)
    

    This code opens the PDF file in a new process.  You can use as many Arguments as you need (or that are allowed by Acrobat).  The string literal in the Arguments line above can also be a variable that contains the path and filename of the PDF you want to open.


    Doug

    SEARCH ... then ask
    Monday, July 27, 2009 2:46 AM
  • try enclosing the Character with braces

    SendKeys.Send("{:}")


    Asgar
    Monday, July 27, 2009 11:40 AM
  • I have been away for a while, but when I got back I tried enclosing the character with braces.  this also yielded a Q. 
    Monday, September 14, 2009 12:50 AM
  • Thank you very much for this suggestion.  It does appear to work!!!!

    ___________________________________________________________

    Phokaeas
    Monday, September 14, 2009 12:53 AM