如何在自动热键中使用数组? [英] How to use array in autohotkey?

查看:67
本文介绍了如何在自动热键中使用数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是AutoHotKey的新手,不熟悉其语法.我在网上搜索过,但找不到有用的示例.

I'm new to AutoHotKey and not familiar with its grammar. I've searched on the web but can't find usefully example.

看看下面的图.

+---+---+---+---+-------------------
| a | b | c | d |                         (1)
+---+---+---+---+-------------------
              ^
              |


+---+---+---+---+-------------------
| a | b | c | d |                         (2)
+---+---+---+---+-------------------
          ^
          |


+---+---+---+---+-------------------
| a | b | c | d |                         (3)
+---+---+---+---+-------------------
  ^
  |

+---+---+---+---+-------------------
| a | b | c | d |                         (4)
+---+---+---+---+-------------------
              ^
              |

我想记录一些字符串并在其中导航.例如,在程序启动时创建了数组my_array.如果用户按ctrl + c,则将选定的文本(假设它是字符串a)复制到剪贴板中,并将其附加到my_array上.如果用户按下另一个ctrl + c,则b被复制到剪贴板中,并且也被附加到my_array上.参见(1),现在将a,b,c,d附加到my_array上,并且d在剪贴板中.现在,如果用户按alt + left_arrow,则c被复制到剪贴板,请参见(2).现在,如果用户按alt + left_arrow 2次,则a在剪贴板中,请参阅(3).用户可以按alt + right_arrow 3次以返回其剪贴板中的d,请参阅(4).此时,用户仍然可以按ctrl + c将数据附加到my_array,然后按alt + left_arrow或alt + right_arrow在数组中四处移动以取回数据.

I want to record some strings and navigate in them. For example, an array my_array was created when the program starts. If the user pressed ctrl+c, then the selected text (let's say it's string a) was copied into clipboard and also it was appended to my_array. If the user pressed another ctrl+c, then b was copied into clipboard and also it was appended to my_array. See (1), now a, b, c, d was appended to my_array and d is in clipboard. Now if the user press alt+left_arrow, then c was copied to clipboard, see (2). Now if the user pressed alt+left_arrow 2 times, a is in clipboard, see (3). The user can press alt+right_arrow 3 times to get back d in its clipboard, see (4). At this time, the user can still press ctrl+c to appended data to my_array and press alt+left_arrow or alt+right_arrow to move around in the array to get data back.

实际上,对我来说,这很容易用其他一些熟悉的语言实现,但是我很难在AutoHotKey中实现它.有人可以帮忙吗?

Actually to me this is easy to implement in some other familiar languages, but I have difficult to implement it in AutoHotKey. Anyone can help?

谢谢.

推荐答案

下面是将复制的Excel数据放入数组的示例.

Here is an example of putting copied Excel data into an array.

MyClipBoard=%ClipBoard% ; Remove any non-text (format) data

Loop, parse, MyClipBoard, `n,`r ; Place Excel content from clipboard in 2 dimentional Array
{ ; Start-Loop Read through each Line (record) in the ClipBoard data from Excel
  FullRecord:=A_LoopField ; Put a whole row in the variable FullRecord
  RecordNumber:=A_Index ; Store the current record (row) number.
  Loop, parse, FullRecord, %A_Tab% ; Parse the row content (FullRecord) in separate fields
  { ; Start-Loop Read through each Field in the ClipBoard data from Excel
    FieldNumber:=A_Index ; Store the current Field number.
    Array%RecordNumber%_%FieldNumber% := A_LoopField ; Array1_1 is Excel Row 1 column A, Array1_2 = Excel Row 1 column B
  } ; End-Loop Read through each Field in the ClipBoard data from Excel
} ; End-Loop Read through each Line (record) in the ClipBoard data from Excel

如果您需要更多示例来帮助您前进,请告诉我.
好了,这里有更多示例,您可以通过查看其他答案中的示例来进行清理,例如使用Variable ++而不是Variable + = 1

If you need more examples to get you going, let me know.
OK here are some more examples, you could clean this up by looking at the examples in the other answers like using Variable++ instead of Variable +=1

; Read data from text file into one dimentional Array
ArrayCount = 0
Loop, Read, %A_ScriptDir%\SearchTerms.txt ; This loop retrieves each line from the file, one at a time.
{
    ArrayCount += 1  ; Keep track of how many items are in the array.
    Array%ArrayCount% := A_LoopReadLine ; Store this line in the next array element.
}


TextCounter = 1
IniWrite, %TextCounter%, C:\Temp\SearchTerms.ini, Counter, Nr ; Write counter in ini so I can restart at latest counter

SearchText:= Array1 ; Put data from Array1 into variable SearchText
MouseClick, left
Send, %SearchText%{Enter}
SplashTextOn, 200, 20,Searchterm,F%TextCounter% %SearchText%
WinMove, Searchterm, , , 0
Return

Browser_Favorites::
IniRead, TextCounter, C:\Temp\SearchTerms.ini, Counter, Nr ; Read latest counter
TextCounter += 1
IniWrite, %TextCounter%, C:\Temp\SearchTerms.ini, Counter, Nr
SearchText:=Array%TextCounter% ; Put data from Array+number into variable SearchText

; Examples with Array of 2 deep.

MyClipBoard=%ClipBoard% ; Remove any non-text (format) data

Loop, parse, MyClipBoard, `n,`r ; Place Excel content from clipboard in 2 dimentional Array
{ ; Start-Loop Read through each Line (record) in the ClipBoard data from Excel
  FullRecord:=A_LoopField ; Put a whole row in the variable FullRecord
  RecordNumber:=A_Index ; Store the current record (row) number.
  Loop, parse, FullRecord, %A_Tab% ; Parse the row content (FullRecord) in separate fields
  { ; Start-Loop Read through each Field in the ClipBoard data from Excel
    FieldNumber:=A_Index ; Store the current Field number.
    Array%RecordNumber%_%FieldNumber% := A_LoopField ; Array1_1 is Excel Row 1 column A, Array1_2 = Excel Row 1 column B
  } ; End-Loop Read through each Field in the ClipBoard data from Excel
} ; End-Loop Read through each Line (record) in the ClipBoard data from Excel



DLCounter:=1
DLSub:=1
DLData:=Array%DLCounter%_1
While (DLData <> "")
{
    While (DLData <> "")
    {
        MsgBox, %DLData%
        DLSub += 1
        DLData:=Array%DLCounter%_%DLSub%
    }
    DLSub:=1
    DLCounter += 1
    DLData:=Array%DLCounter%_%DLSub%
}
Return

这可能不是最干净的代码,但是它将使您了解可以做什么.

It might not be the cleanest code, but it will give you an idea what you can do.

这篇关于如何在自动热键中使用数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆