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.
SendInput array
Re: SendInput array
Can't see your array, so let's create one ...
Not tested.
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
Re: SendInput array
Code: Select all
msgbox,, %DataArray[1]%
Code: Select all
SendInput % DataArray[A_Index]
Re: SendInput array
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
Re: SendInput array
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.
Re: SendInput array
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.
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
Windows 10 Pro 64 bit - Autohotkey v1.1.30.01 64-bit Unicode
Re: SendInput array
The MsgBox command corretly gives me DataArray[1] but both the sendinputs fail
Re: SendInput array
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::
Re: SendInput array
w::MsgBox,,% DataArray[1]
Re: SendInput array
The MsgBox is showing the DataArray[1] correctly, just not the SendInput
Re: SendInput array
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 "forced expression"
Re: SendInput array
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
Re: SendInput array
I even used multiple [identical] occurrences, displaying each one with no problem, but still had the same problem
Re: SendInput array
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]%
Re: SendInput array
Total janky workaround, but if it's only failing with SendInput, could you just do something like MyVar := DataArray[1] and then SendInput %MyVar%?
Re: SendInput array
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
- FanaticGuru
- Posts: 1906
- Joined: 30 Sep 2013, 22:25
Re: SendInput array
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.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.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: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:
FG
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]
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]
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]
The first line of the clipboard can also be displayed even shorter:
Code: Select all
MsgBox % StrSplit(Clipboard, "`n").1
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
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