【问题标题】:changing a variable and using it as a key更改变量并将其用作键
【发布时间】:2014-11-05 12:57:47
【问题描述】:

我买了一个新鼠标,上面有一个滚轮,我已经做了一个变量(Quote_Selector)增加或减少辅助鼠标滚轮转动的方式。此变量中的整数也是定义我的按钮从数组发送的消息的关键。问题是试图将 Quote_Selector 链接为一个键,以提取显示的数组中的消息并发送它。我的目标是尽量让它尽可能干净。我什至尝试过使用 对于表达式中的键 [,value] 但我似乎想不出任何东西。我正在使用 AutoHotKey 语言和软件。

; Declare Variables
Quote_Selector = 0
Min_Selector_Range = 0
Max_Selector_Range = 3

; Declare Message Choices
MessageArray := []
MessageArray[0] := "Darude - Sandstorm"
MessageArray[1] := "Rekt"
MessageArray[2] := "I cry all the time"
MessageArray[3] := "My anaconda don't"
return

; Forward Key Command
$=::
{
If Quote_Selector < %Max_Selector_Range%
Quote_Selector ++
Send, %Quote_Selector%
}
return

; Backward Key Command
$-::
{
If Quote_Selector > %Min_Selector_Range%
Quote_Selector --
Send, %Quote_Selector%
}
return

; Enter Chat Command
$0::
{
Send, {Enter}
Send, /all{space} %value%
Send, {enter}
}
return

【问题讨论】:

  • 您需要编辑并添加一个标签,表明您正在使用的语言/技术。
  • 我修好了,你能告诉我该怎么做吗?

标签: arrays variables key autohotkey


【解决方案1】:
; Declare Variables
Quote_Selector := 0
Min_Selector_Range := 0
Max_Selector_Range := 3

; Declare Message Choices
MessageArray := []
MessageArray[0] = "Darude - Sandstorm"
MessageArray[1] = "Rekt"
MessageArray[2] = "Ready to meme"
MessageArray[3] = "My anaconda don't"
return

; Forward Key Command
$=::
If (Quote_Selector < Max_Selector_Range)
{
    Quote_Selector := Quote_Selector + 1
}
return

; Backward Key Command
$-::
If (Quote_Selector > Min_Selector_Range)
{
    Quote_Selector := Quote_Selector - 1
}
return

; Enter Chat Command
$0::
    Send, {Enter}
    CurrentMessage := MessageArray[%Quote_Selector%]
    Send, /all{Space} %CurrentMessage%
    Send, {Enter}
    CurrentMessage := ""
return

显示的代码使用两个键将消息更改为上一个或下一个,然后按发送按钮发送数组中提供的文本。

【讨论】:

    【解决方案2】:

    试试这个:

    ; Declare Variables
    Quote_Selector := 0
    Min_Selector_Range := 0
    Max_Selector_Range := 3
    
    ; Declare Message Choices
    MessageArray := []
    MessageArray[0] := "Darude - Sandstorm"
    MessageArray[1] := "Rekt"
    MessageArray[2] := "I cry all the time"
    MessageArray[3] := "My anaconda don't"
    return
    
    ; Forward Key Command
    $=::
    If (Quote_Selector < Max_Selector_Range)
    {
        Quote_Selector := Quote_Selector + 1
        CurrentMessage := MessageArray[Quote_Selector]
        Send, %CurrentMessage%
        CurrentMessage := ""
    }
    return
    
    ; Backward Key Command
    $-::
    
    If (Quote_Selector > Min_Selector_Range)
    {
        Quote_Selector := Quote_Selector - 1
        CurrentMessage := MessageArray[Quote_Selector]
        Send, %CurrentMessage%
        CurrentMessage := ""
    }
    return
    
    ; Enter Chat Command
    $0::
        Send, {Enter}
        Send, /all{space} %value%
        Send, {enter}
    return
    

    这是您希望脚本执行的操作吗?


    你的错误:

    1. 始终将 { 放在新行中的 if 语句条件之后,而不是在 if 语句之前。
    2. 这不是实际错误,但始终尝试使用 := 而不是 = 来分配数值。
    3. 始终将if 语句条件括在() 中。
    4. 据我所知,您不能通过Send 命令直接使用数组项。将数组项放到另一个变量中,然后将该变量与 Send 命令一起使用。
    5. 热键不需要包含在{} 中。


    另外,请始终使用来自http://ahkscript.org/ 的 AutoHotkey 及其文档(当前最新版本,新官网)! AutoHotkey 及其来自 autohotkey.com 的文档已过时,您在使用它们时可能会遇到一些问题!

    【讨论】:

    • 你是最棒的!我摆弄了这个建议,结果发现我需要在 Quote_Selector 周围加上 % 来定义它的确切值。我将为此提出实际的解决方案,以展示您在帮助方面的能力!谢谢!
    • @GraemeChew 谢谢 :) 很高兴为您提供帮助。
    猜你喜欢
    • 2014-10-20
    • 1970-01-01
    • 1970-01-01
    • 2020-07-20
    • 2013-09-27
    • 1970-01-01
    • 2017-11-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多