autohotkey - 数字的值没有从字典中提取

标签 autohotkey

我有一本包含字母和数字的字典,我可以很好地获取字母键的值,但不能获取数字键的值,即使它们包含在 "中。这对于问题来说并不重要,但只是在如果您想知道其中包含的 bluscream.ahk 文件是什么样的: https://github.com/Bluscream/ahk-scripts/blob/master/Lib/bluscream.ahk

我尝试了代码中可以看到的内容。我不知道该怎么办

; Version 1
; Date 02/02/2019
#Include <bluscream>
#SingleInstance Force
Process Priority,, Below Normal
SetWorkingDir %A_ScriptDir%
#Warn
#Persistent
SetKeyDelay, 150
game_name := "LEGO" ; LEGO Jurassic World
game_title := "ahk_class TTalesWindow" ; ahk_exe LEGOJurassicWorld_DX11.EXE

chars := { "B" : "{Up}", "C" : "{Up 2}", "D" : "{Up 3}", "E" : "{Up 4}", "F" : "{Up 5}", "G" : "{Up 6}", "H" : "{Up 7}", "J" : "{Up 8}", "K" : "{Up 9}", "L" : "{Up 10}", "M" : "{Up 11}", "N" : "{Up 12}", "O" : "{Up 13}", "P" : "{Up 14}", "Q" : "{Up 15}", "R" : "{Up 16}", "S" : "{Down 18}", "T" : "{Down 17}", "U" : "{Down 16}", "V" : "{Down 15}", "W" : "{Down 14}", "X" : "{Down 13}", "Y" : "{Down 12}", "Z" : "{Down 11}", "0" : "{Down 10}", "1" : "{Down 9}", "2" : "{Down 8}", "3" : "{Down 7}", "4" : "{Down 6}", "5" : "{Down 5}", "6" : "{Down 4}", "7" : "{Down 3}", "8" : "{Down 2}", "9" : "{Down}" }

file := "codes.txt"

global noui := false
scriptlog("Started logging here...")

FileRead, LoadedText, %file%
codes := StrSplit(LoadedText, "`n", "`r")


Loop, % codes.MaxIndex()
{
    if !(WinActive(game_title)) {
        TrayTip, AutoHotKey, Bringing %game_name% to front to enter code...
        Sleep, 1000
        WinWaitActive, %game_title%
    }

    code := StrStrip(codes[A_Index])
    length := StrLen(code)
    FormatTime, timestamp, A_Now, hh:mm:ss
    scriptlog("[" . timestamp . "] Now processing code: " . code . " [" . length . "] (`r`n", "", true)
    splitted_code := StrSplit(code)
    for i, char in splitted_code {
        tosend := chars[char]
        scriptlog("i:" . i . " char:" . char . " tosend:" . tosend . "`r`n", "", true)
        if (tosend){
            SendEvent, % tosend
        }
        if (i < length)
            SendInput, {Right}
    }
    scriptlog(")`r`n","",true)
    SendInput, {Enter}
}

预期结果:

[11:17:43] Started logging here...
[11:17:46] Now processing code: 28SPSR [6] (
i:1 char:2 tosend:{Down 8}
i:2 char:8 tosend:{Down 2}
i:3 char:S tosend:{Down 18}
i:4 char:P tosend:{Up 14}
i:5 char:S tosend:{Down 18}
i:6 char:R tosend:{Up 16}
)

实际结果:

[11:17:43] Started logging here...
[11:17:46] Now processing code: 28SPSR [6] (
i:1 char:2 tosend:
i:2 char:8 tosend:
i:3 char:S tosend:{Down 18}
i:4 char:P tosend:{Up 14}
i:5 char:S tosend:{Down 18}
i:6 char:R tosend:{Up 16}
)

最佳答案

看起来像是对象声明的错误。关于字符串与数字的问题。

使用不带引号的数字可以解决该问题。

而且,在声明对象后执行此操作也可以解决问题:

for k,v in chars
    chars[k] := v

您可以在官方板上补一个bug:https://www.autohotkey.com/boards/

关于autohotkey - 数字的值没有从字典中提取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54498365/

相关文章:

autohotkey - 无法让坐标模式在一个非常简单的脚本中工作

windows - autohotkey 脚本速度和防止垃圾点击

AutoHotKey - 如何截取屏幕截图并将其粘贴到 *.jpg 文件?

powershell - 如何使用通用脚本语言从内置扬声器发出 BIOS 蜂鸣声?

autohotkey - 向上/向下键在 Onenote 2016 中对于 Autohotkey 不起作用

autohotkey - 我如何使用 AutoHotkeys 的相对路径

Autohotkey:按住时只发送一次

windows - AHK Always on Top 不适用于 Windows 文件资源管理器和其他 Windows 系统窗口?

autohotkey - AU3_Spy.exe 是什么?我在哪里可以找到它?

autohotkey - 使 AutoHotKey 忽略 Alt 作为菜单键