【问题标题】:Can't get functions to work properly无法使功能正常工作
【发布时间】:2018-02-19 06:05:52
【问题描述】:

所以我刚开始使用自动热键,但在让我的函数和变量很好地发挥作用时遇到了一些麻烦..

这就是我所拥有的:

PSbri0 = C:\Controls\Set_0Bri_PS.bat
PSbri50 = C:\Controls\Set_50Bri_PS.bat
PSbri100 = C:\Controls\Set_100Bri_PS.bat
HPbri0 = C:\Controls\Set_0Bri_HP.bat
HPbri50 = C:\Controls\Set_50Bri_HP.bat
HPbri100 = C:\Controls\Set_100Bri_HP.bat

Run %PSbri0%

current_setting := 0 
current_power := 0 ;Power Saver = 0 High performance = 1

setPower(){
    global current_power
    if(%current_power% == 1){
        MsgBox Pow 1
        %current_power% := 0
    }else{
        MsgBox pow 2
        %current_power% := 1
    }   
}

getChange(direction)
{
    global current_power
    MsgBox dir %direction%
    if (%current_power% == 0){
        ;MsgBox run 0
        getChangePS(%direction%)
    }
    else if (%current_power% == 1){
        ;MsgBox run 1
        getChangeHP(%direction%)    
    }
}

getChangePS(direction)
{
    global current_setting
    ;MsgBox %current_setting%
    MsgBox Direction: %direction%

    if(direction == 1){
        ;MsgBox %current_setting%
        if(%current_setting% == 0){
        }
        else if(%current_setting% == 50){
            %current_setting% := 0
            Run %PSbri0%
        }
        else if(%current_setting% == 100){
            %current_setting% := 50
            Run %PSbri50%
        }
    }    
    else if(direction == 0){
    ;MsgBox %current_setting%
        if(%current_setting% == 100){
        }
        else if(%current_setting% == 50){
            %current_setting% := 100
            Run %PSbri100%
        }
        else if(%current_setting% == 0){
            %current_setting% := 50
            Run %PSbri50%
        }
    }
}
getChangeHP(direction)
{
    global

    if(direction == 1){
        ;MsgBox %current_setting%
        if(%current_setting% == 0){
        }
        else if(%current_setting% == 50){
            %current_setting% := 0
            Run %HPbri0%
        }
        else if(%current_setting% == 100){
            %current_setting% := 50
            Run %HPbri50%
        }
    }    
    else if(direction == 0){
        ;MsgBox %current_setting%
        if(%current_setting% == 100){
        }
        else if(%current_setting% == 50){
            %current_setting% := 100
            Run %HPbri100%
        }
        else if(%current_setting% == 0){
            %current_setting% := 50
            Run %HPbri50%
        }
    }
}

^F5:: getChange(0)
^F6:: getChange(1)
!^P:: setPower()

我一直在查看文档和在线其他帖子,但我似乎无法找出我做错了什么..

我的预期目标是能够轻松切换电源配置文件我在开始时声明了 6 个配置文件,其中包含高性能 (HP) 级别和三个省电级别 (PS) 我想使用 Alt+Ctrl+P 在电源选项和 F5/F6 之间切换 增加亮度或调暗屏幕。 bat 文件完美运行,它们会更改我的设置,所以我知道这不是问题..

我已经尝试过首先在函数中不使用全局声明,但这没有用,声明也没有。

感谢你们的帮助!

【问题讨论】:

    标签: function global autohotkey


    【解决方案1】:

    抱歉,您在太多地方使用了 %

    它的使用取决于你在哪里使用变量,如果它在一个表达式中你不使用 % 围绕变量,在大多数其他地方你这样做,接下来的事情就是知道你什么时候输入接受表达式的东西,这需要一点时间来学习,但这里有两个链接可能会有所帮助

    http://ahkscript.org/docs/Variables.htm#Expressions

    http://www.autohotkey.com/board/topic/118109-hard-rules-when-using-variables/

    这里有一个小例子说明它的外观

    setPower(){
        global current_power
        if (current_power == 1){
            MsgBox Pow 1
            current_power := 0
        }else{
            MsgBox pow 2
            current_power := 1
        }   
    }
    
    getChange(direction)
    {
        global current_power
        MsgBox dir %direction%
        if (current_power == 0){
            ;MsgBox run 0
            getChangePS(direction)
        }
        else if (current_power == 1){
            ;MsgBox run 1
            getChangeHP(direction)    
        }
    }
    

    希望对你有帮助

    【讨论】:

    • 谢谢你!你是绅士和学者!这解决了我的问题,并且我对这种语言有了更好的理解。
    猜你喜欢
    • 2017-09-23
    • 2013-11-06
    • 2013-10-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多