Page 1 of 1

ControlSend pressing Shift during send?

Posted: 16 Oct 2018, 17:18
by cws
I'm using COM to send values from Excel into the command prompt, and sometimes during ControlSend, it appears that AHK is pressing shift.

For example,

Code: Select all

start %windir%\explorer.exe 
is getting sent as

Code: Select all

start %windir5|explorer.exe
The full code I am sending is below. Is there some kind of Send parameter I need to define to prevent this from happening

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

!^i::

xl := ComObjCreate("Excel.Application")
xl.Visible := true
FilePath := "C:\Users\folder\file.xlsx"
xl.Workbooks.Open(FilePath)

values := {}
	for Cell in Xl.Range("A1:A5").Cells
		if !(Cell.text="")
			Values.Push(Cell.Text)
	
xl.Quit

SetKeyDelay , 30

run cmd.exe

for key, val in values
	{
		WinActivate, ahk_exe cmd.exe
		WinWait, ahk_exe cmd.exe
		ControlSendRaw ,, % val, ahk_exe cmd.exe
		WinWait, ahk_exe cmd.exe
		ControlSend ,, {enter}, ahk_exe cmd.exe
		WinWait, ahk_exe cmd.exe

	}
MsgBox, DONE


Re: ControlSend pressing Shift during send?

Posted: 16 Oct 2018, 18:09
by cws
I was able to make it more reliable by adding SetKeyDelay, but it still fails for some inputs when my computer hangs up trying to access the network folder locations. Maybe make the SetKeyDelay longer or the press longer?

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
SendMode Input


!^i::

xl := ComObjCreate("Excel.Application")
xl.Visible := true
FilePath := "C:\Users.yadayada.xlsx"
xl.Workbooks.Open(FilePath)

values := {}
	for Cell in Xl.Range("A1:A100").Cells
		if !(Cell.text="")
			Values.Push(Cell.Text)
	
xl.Quit

SetKeyDelay , 20, 20

run cmd.exe

for key, val in values
	{
		WinActivate, ahk_exe cmd.exe
		WinWait, ahk_exe cmd.exe
		Send ,, %val%, ahk_exe cmd.exe
		WinWait, ahk_exe cmd.exe
		ControlSend ,, {enter}, ahk_exe cmd.exe
		WinWait, ahk_exe cmd.exe

	}
MsgBox, DONE

Return

Re: ControlSend pressing Shift during send?

Posted: 16 Oct 2018, 19:18
by jeeswg
Try:
ControlSend ,, % "{Text}" val, ahk_exe cmd.exe

Re: ControlSend pressing Shift during send?

Posted: 17 Oct 2018, 04:02
by rommmcek
You might also try:

Code: Select all

Clipboard:=""
Clipboard:=var:="start %windir%\explorer.exe"
ClipWait, 1
ControlSend ,, ^v, ahk_exe cmd.exe
Generally is this much faster then sending a string.

P.s.: Since you're already using COM for accessing spreadsheet, you should attempt to use COM for Cmd too. Not as easy as ControlSend, but provides feedback.