SendInput array

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
RonJeanJr
Posts: 20
Joined: 01 Mar 2018, 12:35

SendInput array

22 Mar 2018, 09:33

So I am finding myself unable to use SendInput to send an array. I've verified that Data[1] is something along the lines of HELLO WORLD through the msgbox display, but when I use
SendInput % Data[1]
One line under that, on notepad, runbar, anything, it's just pure blank.
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: SendInput array

22 Mar 2018, 09:41

Can't see your array, so let's create one ...

Code: Select all

array := []
array[1] := "A"
array[2] := 2
array[3] := (A_Now/10) - 3 * 0.5

F12::
    Random, no, 1, array.Length()
    SendInput % array[no]
    Return
Not tested.
RonJeanJr
Posts: 20
Joined: 01 Mar 2018, 12:35

Re: SendInput array

22 Mar 2018, 09:49

Code: Select all

msgbox,, %DataArray[1]%
Output is shown as THE APPLE IS GREEN

Code: Select all

SendInput % DataArray[A_Index]
Out is nothing / blank
RonJeanJr
Posts: 20
Joined: 01 Mar 2018, 12:35

Re: SendInput array

22 Mar 2018, 09:50

I've tried that in the runbar, notepad, but nothing shows up. The main program is farm more complicated but I can link if completely necessary
RonJeanJr
Posts: 20
Joined: 01 Mar 2018, 12:35

Re: SendInput array

22 Mar 2018, 09:54

Code: Select all

Stuff:
	Data := []
	WinActivate, Excel
	WinWaitActive, Excel
	ClipSaved := ClipboardAll
	SendInput, ^{Home}
	Sleep, 500
	SendInput, ^a
	Sleep, 500
	SendInput, ^a
	Sleep, 500
	SendInput, ^{Insert}
	Sleep, 500
	Data := Clipboard
	Clipboard := ClipSaved
	StringSplit, DataArray, Data, `n
	ArrayCount := 0
	Loop
		IF DataArray%A_Index%
			ArrayCount += 1
		ELSE
			BREAK
	Loop, %ArrayCount%
		IF DataArray%A_Index%
			DataArray[A_Index] := DataArray%A_Index%
	Loop %ArrayCount%
		IF NOT DataArray[A_Index]
			DataArray.RemoveAt(A_Index)
;delme
msgbox,, %DataArray[1]%
	IF ArrayCount > 69
		{
		ArrayCount := 70
		AutoLogout := 1
		}
	ELSE
		AutoLogout := 0
	WinActivate, %chosenwindow%
	WinWaitActive, %chosenwindow%
	Loop %ArrayCount%
		{
		IF FileExist("SearchBox1.BMP")
			{
			ImageSearch, X, Y, 0, 0, 1500, 1500, *42 SearchBox1.BMP
			IF NOT ErrorLevel
				{
				Image Pattern Recognition Successful(X,Y,20,20,500)
				SendInput, ^{a}
				Sleep, 500
				SendInput, {Del}
				Sleep, 500
				SendInput, {Esc}
				Sleep, 500
				SendInput % DataArray[A_Index]
				Sleep, 500
				SendInput, {Enter}
				Sleep, 3000
				}
			ELSE IF FileExist("SearchBox2.BMP")
				{
				ImageSearch, X, Y, 0, 0, 1500, 1500, *42 SearchBox2.BMP
				IF NOT ErrorLevel
					{
					Image Pattern Recognition Successful(X,Y,20,20,500)
					SendInput, ^{a}
					Sleep, 500
					SendInput, {Del}
					Sleep, 500
					SendInput, {Esc}
					Sleep, 500
					SendInput % DataArray[A_Index]
					Sleep, 500
					SendInput, {Enter}
					Sleep, 3000
					}
				}
			}
RETURN


w::
	SendInput % DataArray[1]
	return
	
Last edited by RonJeanJr on 22 Mar 2018, 10:01, edited 1 time in total.
Odlanir
Posts: 659
Joined: 20 Oct 2016, 08:20

Re: SendInput array

22 Mar 2018, 09:55

The proposed statement should display a msgbox with THE TITLE ( not the message ) set to the contents of DataArray[1].
I would like to see how you can avoid the message "The following variable name contains an illegal character:" running it.

Code: Select all

msgbox,, %DataArray[1]%
____________________________________________________________________________
Windows 10 Pro 64 bit - Autohotkey v1.1.30.01 64-bit Unicode
RonJeanJr
Posts: 20
Joined: 01 Mar 2018, 12:35

Re: SendInput array

22 Mar 2018, 09:55

The MsgBox command corretly gives me DataArray[1] but both the sendinputs fail
RonJeanJr
Posts: 20
Joined: 01 Mar 2018, 12:35

Re: SendInput array

22 Mar 2018, 09:56

I tried msgbox,, %DataArray[1]% as well, thinking that perhaps I had the syntax wrong, and it failed to put other than blank also, in both the main portion and the w::
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: SendInput array

22 Mar 2018, 09:58

w::MsgBox,,% DataArray[1]
RonJeanJr
Posts: 20
Joined: 01 Mar 2018, 12:35

Re: SendInput array

22 Mar 2018, 10:01

The MsgBox is showing the DataArray[1] correctly, just not the SendInput
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: SendInput array

22 Mar 2018, 10:06

Meanwhile, I've tested my script from above, and it worked flawlessly, and showed me that SendInput won't throw an error if (ab)used using a :arrow: "forced expression"
RonJeanJr
Posts: 20
Joined: 01 Mar 2018, 12:35

Re: SendInput array

22 Mar 2018, 10:13

Righton, I think my problem stems from the fact that I'm copying information from an Excel file, as I don't encounter this when copying from anywhere else
RonJeanJr
Posts: 20
Joined: 01 Mar 2018, 12:35

Re: SendInput array

22 Mar 2018, 10:14

I even used multiple [identical] occurrences, displaying each one with no problem, but still had the same problem
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: SendInput array

22 Mar 2018, 10:16

Code: Select all

Loop, %ArrayCount%
		IF DataArray%A_Index%
			DataArray[A_Index] := DataArray%A_Index%
	Loop %ArrayCount%
		IF NOT DataArray[A_Index]
			DataArray.RemoveAt(A_Index)
;delme
msgbox,, %DataArray[1]%
I'm sorry, but before you even think about to go on with your project you have to review AHK's help regarding variables > (forced) expressions/functions and arrays, so you can master the syntax correctly. Otherwise, this will end up in blood, sweat & tears :lolno: :shifty:
MaxAstro
Posts: 557
Joined: 05 Oct 2016, 13:00

Re: SendInput array

22 Mar 2018, 10:19

Total janky workaround, but if it's only failing with SendInput, could you just do something like MyVar := DataArray[1] and then SendInput %MyVar%?
RonJeanJr
Posts: 20
Joined: 01 Mar 2018, 12:35

Re: SendInput array

22 Mar 2018, 10:26

Thank you - that did the trick! I would've expected better results out of such a great compiler, but I've been finding its limits more and more lately where I have to resort to simple tricks like this as workarounds. Thanks again
User avatar
FanaticGuru
Posts: 1906
Joined: 30 Sep 2013, 22:25

Re: SendInput array

23 Mar 2018, 14:57

I find this thread confusing so for future googlers so as to be more clear.

AHK has no problem with SendInput or MsgBox in relation to arrays.

Code: Select all

data := ["stuff"]
SendInput % data[1]
MsgBox % data[1]
MsgBox,, % data[1]
You do have to use the % to tell AHK to evaluate what follows as an expression but that is common.

Also this will not work because DataArray is never defined as an array.

Code: Select all

Data := Clipboard
StringSplit, DataArray, Data, `n
ArrayCount := 0
Loop
	IF DataArray%A_Index%
		ArrayCount += 1
	ELSE
		BREAK
Loop, %ArrayCount%
	IF DataArray%A_Index%
		DataArray[A_Index] := DataArray%A_Index%
Loop %ArrayCount%
	IF NOT DataArray[A_Index]
		DataArray.RemoveAt(A_Index)
msgbox,, % DataArray[1]
You can put this: DataArray := {} somewhere before that code and it will function to some extent.

But it seems to be just a bunch of work that can be replaced with this:

Code: Select all

DataArray := StrSplit(Clipboard, "`n")
msgbox,, % DataArray[1]
This will display the first line of the clipboard. Well display as the 'title' of a message box which in itself seems strange.

The first line of the clipboard can also be displayed even shorter:

Code: Select all

MsgBox % StrSplit(Clipboard, "`n").1
FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: filipemb, mikeyww and 187 guests