数字的价值没有得到从字典中提取

问题描述 投票:2回答:1

我有一个包含字母和数字,我可以得到的字母键就好了,但不是从即使它们包含在“数字的人。这不是针对这个问题很重要,但以防万一你”的值的字典重新想知道其中的包括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}
)
autohotkey
1个回答
1
投票

貌似对象说明的一个bug。关于字符串VS数字的问题。

使用数字不包括引号去掉的问题。

而且,声明该对象后,这样做解决了这个问题太:

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

您可以填写在官方板中的错误:https://www.autohotkey.com/boards/

© www.soinside.com 2019 - 2024. All rights reserved.