Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Autohotkey Can';t获取自动热键以计算if语句中的变量_Autohotkey - Fatal编程技术网

Autohotkey Can';t获取自动热键以计算if语句中的变量

Autohotkey Can';t获取自动热键以计算if语句中的变量,autohotkey,Autohotkey,我试图让Autohotkey计算从剪贴板分配的变量,然后根据变量的内容执行某些操作。代码如下: ^j:: Clipboard := "" ; Must start off blank for detection to work. WinActivate, ahk_exe Excel.exe Send, ^c ; Copy text into Clipboard ClipWait, 2

我试图让Autohotkey计算从剪贴板分配的变量,然后根据变量的内容执行某些操作。代码如下:

^j::
    Clipboard := ""           ; Must start off blank for detection to work.
    WinActivate, ahk_exe Excel.exe

    Send, ^c                        ; Copy text into Clipboard
    ClipWait, 2                     ; wait for it to be copied
    Course := Clipboard             ; Fetch the text into variable
    Clipboard := ""                 ; Reset Clipboard

    MsgBox %Course%                 ; To test is Course is "103"

    if ( Course == 103 ) 
    {
        Correct_Num := 105
        Correct_Title := Art Appreciation
    } 

    send, {Tab}
    send, {Tab}
    send, {Tab}
    send, %Correct_Num%
    send, {Tab}
    send, %Correct_Title%
if语句没有检测到
Course==103
,尽管MsgBox显示103。我试过用103个引号写这句话,我试过
IfEqual
。不确定还要做什么。

所有变量(剪贴板、课程、正确编号和正确标题)必须以空白开头,才能进行检测。否则,它们的最后一个值将保留在内存中

^j::
    Course := "" 
    Correct_Num := "" 
    Correct_Title := "" 
    Clipboard := ""         
    WinActivate, ahk_exe Excel.exe
    WinWaitActive, ahk_exe Excel.exe ; important
    Send, ^c                         ; Copy the preselected text
    ClipWait, 2                      ; Wait for the clipboard to contain data
    if (!ErrorLevel)                 ; If NOT ErrorLevel clipwait found data on the clipboard   
    { 
        Course := Trim(Clipboard)        ; Fetch the text into variable (as suggested by PGilm)
        Clipboard := ""                  ; Reset Clipboard
        if (Course == 103) 
        {
            Correct_Num = 105
            Correct_Title = Art Appreciation
        }
        MsgBox %Course%`n%Correct_Num%`n%Correct_Title%
    }
    else
        MsgBox, The attempt to copy text onto the clipboard failed.
return
所有变量(剪贴板、课程、Correct_Num和Correct_Title)必须以空白开头,以便检测工作。否则,它们的最后一个值将保留在内存中

^j::
    Course := "" 
    Correct_Num := "" 
    Correct_Title := "" 
    Clipboard := ""         
    WinActivate, ahk_exe Excel.exe
    WinWaitActive, ahk_exe Excel.exe ; important
    Send, ^c                         ; Copy the preselected text
    ClipWait, 2                      ; Wait for the clipboard to contain data
    if (!ErrorLevel)                 ; If NOT ErrorLevel clipwait found data on the clipboard   
    { 
        Course := Trim(Clipboard)        ; Fetch the text into variable (as suggested by PGilm)
        Clipboard := ""                  ; Reset Clipboard
        if (Course == 103) 
        {
            Correct_Num = 105
            Correct_Title = Art Appreciation
        }
        MsgBox %Course%`n%Correct_Num%`n%Correct_Title%
    }
    else
        MsgBox, The attempt to copy text onto the clipboard failed.
return
根据我的评论:

^j::
    Clipboard := ""           ; Must start off blank for detection to work.
    WinActivate, ahk_exe Excel.exe

    WinWaitActive, ahk_exe Excel.exe ; important

    Send, ^c                         ; Copy text into Clipboard
    ClipWait, 2                      ; wait for it to be copied
    Course := Trim(Clipboard)        ; Fetch the text into variable
    Clipboard := ""                  ; Reset Clipboard

    MsgBox %Course%                  ; To test is Course is "103"

    Correct_Num =                    ; Clear variables per user3419297 so they don't
    Correct_Title =                  ; contain the results from a prior time the equality
                                     ; was satisfied (else you will get the same results
                                     ; even if Course <> 103 since those variables
                                     ; will still contain the values from earlier)

    ifEqual, Course, 103
    {
        MsgBox Course is equal to 103, Hooray!! 
        Correct_Num := 105
        Correct_Title := Art Appreciation
    } 

    send, {Tab}
    send, {Tab}
    send, {Tab}
    send, %Correct_Num%  ;  will be blank (send nothing) if course not 103
    send, {Tab}
    send, %Correct_Title%  ;  will be blank (send nothing) if course not 103

    ;  return  ;  not sure what the rest of your code does
^j::
剪贴板:=“”;必须从空白处开始检测才能工作。
WinActivate,ahk_exe Excel.exe
WinWaitActive,ahk_exe Excel.exe;重要的
发送,^c;将文本复制到剪贴板
克里普韦特,2;等待它被复制
课程:=修剪(剪贴板);将文本提取到变量中
剪贴板:=“”;重置剪贴板
MsgBox%课程%;测试的过程是“103”
正确的_Num=;清除每个用户的变量3419297,这样它们就不会
正确的标题=;包含来自上一次等式的结果
; 满意(否则您将得到相同的结果
;即使这些变量
;仍将包含以前版本中的值)
如果相等,当然是103
{
MsgBox课程等于103,万岁!!
正确数量:=105
正确的标题:=艺术欣赏
} 
发送,{Tab}
发送,{Tab}
发送,{Tab}
发送,%Correct\u Num%;如果课程不是103,则将为空(不发送任何内容)
发送,{Tab}
发送,标题正确%u%;如果课程不是103,则将为空(不发送任何内容)
;  返回;不确定代码的其余部分是做什么的
Hth

根据我的评论:

^j::
    Clipboard := ""           ; Must start off blank for detection to work.
    WinActivate, ahk_exe Excel.exe

    WinWaitActive, ahk_exe Excel.exe ; important

    Send, ^c                         ; Copy text into Clipboard
    ClipWait, 2                      ; wait for it to be copied
    Course := Trim(Clipboard)        ; Fetch the text into variable
    Clipboard := ""                  ; Reset Clipboard

    MsgBox %Course%                  ; To test is Course is "103"

    Correct_Num =                    ; Clear variables per user3419297 so they don't
    Correct_Title =                  ; contain the results from a prior time the equality
                                     ; was satisfied (else you will get the same results
                                     ; even if Course <> 103 since those variables
                                     ; will still contain the values from earlier)

    ifEqual, Course, 103
    {
        MsgBox Course is equal to 103, Hooray!! 
        Correct_Num := 105
        Correct_Title := Art Appreciation
    } 

    send, {Tab}
    send, {Tab}
    send, {Tab}
    send, %Correct_Num%  ;  will be blank (send nothing) if course not 103
    send, {Tab}
    send, %Correct_Title%  ;  will be blank (send nothing) if course not 103

    ;  return  ;  not sure what the rest of your code does
^j::
剪贴板:=“”;必须从空白处开始检测才能工作。
WinActivate,ahk_exe Excel.exe
WinWaitActive,ahk_exe Excel.exe;重要的
发送,^c;将文本复制到剪贴板
克里普韦特,2;等待它被复制
课程:=修剪(剪贴板);将文本提取到变量中
剪贴板:=“”;重置剪贴板
MsgBox%课程%;测试的过程是“103”
正确的_Num=;清除每个用户的变量3419297,这样它们就不会
正确的标题=;包含来自上一次等式的结果
; 满意(否则您将得到相同的结果
;即使这些变量
;仍将包含以前版本中的值)
如果相等,当然是103
{
MsgBox课程等于103,万岁!!
正确数量:=105
正确的标题:=艺术欣赏
} 
发送,{Tab}
发送,{Tab}
发送,{Tab}
发送,%Correct\u Num%;如果课程不是103,则将为空(不发送任何内容)
发送,{Tab}
发送,标题正确%u%;如果课程不是103,则将为空(不发送任何内容)
;  返回;不确定代码的其余部分是做什么的

Hth

代码对我很有用。你一定是在复制不是
103
@2501的东西。当我将变量Course打印到消息框中时,它的读数为103。AHK没有办法把某个东西叫做整数,是吗?实际上,当我注释掉
WinActive
并在记事本中使用
103
时,它确实起了作用。我将查看是否可以将Excel中的单元格格式化为数字,但它应该已经这样做了,我认为可能只需修剪非打印字符即可:
Course:=Trim(剪贴板)
。您还可以根据@user3419297的回答使用
WinWaitActive,ahk_exe Excel.exe
语句。代码对我有效。你一定是在复制不是
103
@2501的东西。当我将变量Course打印到消息框中时,它的读数为103。AHK没有办法把某个东西叫做整数,是吗?实际上,当我注释掉
WinActive
并在记事本中使用
103
时,它确实起了作用。我将查看是否可以将Excel中的单元格格式化为数字,但它应该已经这样做了,我认为可能只需修剪非打印字符即可:
Course:=Trim(剪贴板)
。您还可以根据@user3419297的回答使用
WinWaitActive,ahk_exe Excel.exe
语句。我发现上述代码有一个问题:如果变量“Course”等于“103”,您将获得其他变量的正确值,这些值将保留在脚本内存中。下次按^j复制预选文本时,即使变量“Course”不等于“103”,也会得到相同的值。明白,@user3419297(我在上面进行了相应的编辑)。当然,我们不知道OP的其余代码是做什么的(不包括“return”)。除非OP想提供更多/更好的上下文。啊,所以我的答案并不比你的好,而你是第一个(我看到你编辑了你的答案以接受我的建议)。我会相应地告诉你。如果OP确认
修剪(剪贴板)
使解决方案起作用(但我希望得到一些代表),我可能可以删除我的答案。我发现上面的代码有一个问题:如果变量“Course”等于“103”,您将得到其他变量的正确值,这些值将保留在脚本的内存中。下次按^j复制预选文本时,将得到相同的值