ControlSend pressing Shift during send?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
cws
Posts: 27
Joined: 02 Oct 2017, 18:11

ControlSend pressing Shift during send?

16 Oct 2018, 17:18

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

cws
Posts: 27
Joined: 02 Oct 2017, 18:11

Re: ControlSend pressing Shift during send?

16 Oct 2018, 18:09

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
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: ControlSend pressing Shift during send?

16 Oct 2018, 19:18

Try:
ControlSend ,, % "{Text}" val, ahk_exe cmd.exe
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
rommmcek
Posts: 1474
Joined: 15 Aug 2014, 15:18

Re: ControlSend pressing Shift during send?

17 Oct 2018, 04:02

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.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: aitaixy, Google [Bot], Nerafius, RandomBoy and 201 guests