VBS SendKeys issue

I cannot seem to get SendKeys to paste into a vbs input box. It copies just fine and can paste into notepad, word and other programs, just not the place I need it to. I can use the keyboard itself and I can paste all day long in the box I am trying to get data entered, but this is supposed to be an automated task. Currently working on trying to set this up to open as html to input and display data but I need to learn alittle more about that first. Can sendkeys paste into vbs? Because it is looking like no. Any advise to get this script working is appreciated.

on error resume next

dim dbconnection, sqlrs, itemno,sqlrs2, ITEM, objData

Const CONNECT_STRING = "provider=SQLOLEDB.1;Presist Security info=True;User ID=sa;Initial Catalog=DEMOGOLF;Data Source=SERVER;password=PASSWORD"

Set WshShell = WScript.CreateObject("WScript.Shell")
set objFSO = CreateObject("Scripting.FileSystemObject")
Set dbconnection = createobject("ADODB.connection")
Set sqlrs = createobject("ADODB.Recordset")
Set sqlrs2 = createobject("ADODB.Recordset")

dbconnection.open CONNECT_STRING

WshShell.AppActivate "Touchscreen Ticket Entry"
WshShell.SendKeys ("%a")
WshShell.SendKeys ("^C")

wsh.sleep 1000

Itemno = InputBox("Enter Item Number:", "Item Number")
WshShell.AppActivate "Item Number"
wsh.sleep 2000
WshShell.SendKeys ("^V")

'-------------------------------------------------------------------------
'-----------Different ways I found and tried-------------------
'-------------------------------------------------------------------------
SendKeys.Send("^{v}")

'WshShell.SendKeys ("+{Ins}")

'WshShell.SendKeys ("^{vk56}")

'SendKeys.KeyDown(Keys.ControlKey)
'SendKeys.PressKey(Keys.V)
'SendKeys.KeyUp(Keys.ControlKey)

'Itemno = WshShell.SendKeys ("^V")
'-------------------------------------------------------------------------
'-------------------------------------------------------------------------
'-------------------------------------------------------------------------
msgbox ("Item Description "&sqlrs2("DESCR")& vbCrLf & "Current Average Cost: $"& ROUND(sqlrs("AVG_COST"),4)& vbCrLf & "Current Margin: "&ROUND(sqlrs2("MARGIN"),4)&"%"&""),0,"Item Number: "&sqlrs("ITEM_NO")
'WshShell.SendKeys "{ENTER}"




sqlrs.open "SELECT * FROM [IM_INV] where ITEM_NO = '"&Itemno&"' AND LOC_ID='MAIN'", CONNECT_STRING
sqlrs2.open "SELECT * FROM [VI_USR_MARGIN] where ITEM_NO = '"&Itemno&"'", CONNECT_STRING
If sqlrs.EOF Then 
    Wscript.Echo "Invalid Item. Please Re-Enter."
Else
msgbox ("Item Description "&sqlrs2("DESCR")& vbCrLf & "Current Average Cost: $"& ROUND(sqlrs("AVG_COST"),4)& vbCrLf & "Current Margin: "&ROUND(sqlrs2("MARGIN"),4)&"%"&""),0,"Item Number: "&sqlrs("ITEM_NO")
END IF

sqlrs.close
dbconnection.close

July 15th, 2015 12:32pm

SendKeys is notoriously unreliable, as you're seeing.
Free Windows Admin Tool Kit Click here and download it now
July 15th, 2015 12:41pm

In this example it would be impossible.

July 15th, 2015 12:54pm

I cannot seem to get SendKeys to paste into a vbs input box.

Would you ever write an application that requires users to type some input blindly, without ever looking at the screen to check where exactly they are? This is precisely what SendKeys does. It would work fine on a single-tasking machine but will fail regularly on a multi-tasking machine because you can never be sure which is the active window at any point in time. Generating Alt-Tab keystrokes by trial and error to switch to another window will work some of the time, then fail again.
Free Windows Admin Tool Kit Click here and download it now
July 15th, 2015 2:17pm

Well it has done very well for many other projects that integrated many more commands.

This project is the only one not working correctly due to inability to paste to input box.

Just need to get it to paste into the input box. Pastes fine into everything else.

Or assign what the WshShell.SendKeys ("^C") has copied to Itemno.

What would other recommend?


July 15th, 2015 2:20pm

What would other recommend?

Rewrite your project so that it does not rely on SendKeys. Any unexpected pop-up, e.g. from some update, will derail your script.
Free Windows Admin Tool Kit Click here and download it now
July 15th, 2015 2:37pm

Do not use inputbox.  If you want the box to timeout then use a "popup" which has a timer.

July 15th, 2015 3:41pm

What would other recommend?

Rewrite your project so that it does not rely on SendKeys. Any unexpected pop-up, e.g. from some update, will derail your script.
  • Proposed as answer by Mike Laughlin Wednesday, July 15, 2015 7:01 PM
Free Windows Admin Tool Kit Click here and download it now
July 15th, 2015 6:33pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics