sendkeys not working in windows xp professional sp3

Discussion in 'Scripting' started by emrefan, Jan 27, 2011.

  1. emrefan

    emrefan Guest

    I have a keyboard macro written in Windows Script and it was working
    when I had Windows XP Professional SP2 (I have the traditional Chinese
    version of XP, if that matters). After installing SP3, it stopped
    working. It seems SP3 is preventing some type of keys to be sent to
    applications. The following test script (NOT my original script, which
    is a bit more complex) demonstrates the problem. If anyone has
    Windows XP Pro + SP3, please try it out and better yet, provide a
    solution / workaround.

    -------------------------------------------- snip
    -----------------------------------------------------------------------------------
    set oShell = WScript.createObject( "WScript.Shell" )

    oShell.run "notepad"
    WScript.sleep 800

    ' Please adapt the window name in following function for your
    ' particular version of Windows XP:

    wndFound = oShell.appActivate( "noname - notepad" )

    if not wndFound then
    WScript.Echo "Window not found, cannot send keys to it"
    WScript.quit
    end if

    ' Sending ctrl-o to start the Open document dialogue box does NOT
    ' work on XP w/ SP3:
    oShell.sendKeys "^O"

    WScript.sleep 100
    oShell.sendKeys "sending plain text works"

    --------------------------------------------- snip
    ---------------------------------------------------------------------
     
    emrefan, Jan 27, 2011
    #1
    1. Advertisements

  2. emrefan

    Tom Lavedas Guest

    Try lower case letters for menu items. I don't know why things
    changed, but they appear to have. The following script (which closes
    the loop around locating the newly opened Notepad window) worked for
    me in XPSP3.

    set oShell = createObject( "WScript.Shell" )

    oShell.run "notepad", 1 False

    ' Please adapt the window name in following function for your
    ' particular version of Windows XP:

    For n = 1 to 10
    WScript.sleep 50
    wndFound = oShell.appActivate( "notepad" )
    if wndFound then exit for
    next

    if not wndFound then
    WScript.Echo "Window not found, cannot send keys to it"
    WScript.quit
    end if

    ' Sending ctrl-o to start the Open document dialogue box does NOT
    ' work on XP w/ SP3:
    oShell.sendKeys "^o" ' lower case only

    WScript.sleep 100
    oShell.sendKeys "sending plain text works"

    _____________________________
    Tom Lavedas
     
    Tom Lavedas, Jan 27, 2011
    #2
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.