简体   繁体   English

无法使功能正常工作

[英]Can't get functions to work properly

So I just got started with auto hotkeys and I'm having a bit o trouble getting my functions and variables to play nicely.. 所以我刚开始使用自动热键,但是让我的函数和变量无法正常播放有点麻烦。

This is what I have: 这就是我所拥有的:

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()

I've been looking over the documentation and through other posts online but I cannot seem to find out what I'm doing wrong.. 我一直在查看文档以及在线上的其他帖子,但似乎无法找出我做错了什么。

My intended goal is to be able to switch power profiles easily I have the 6 profiles declared in the beginning with thee levels of high performance (HP) and three Power Saver levels(PS) I want to use Alt + Ctrl + P to change between power options and the F5 / F6 to add brightness or dim the screen. 我的既定目标是能够轻松切换电源配置文件,我在开始时声明了6个配置文件,其中包含高性能(HP)级别和三个节电级别(PS),我想使用Alt + Ctrl + P在电源选项和F5 / F6增加亮度或使屏幕变暗。 The bat files work perfectly and they change my settings as they should so I know that isn't an issue.. 蝙蝠文件可以完美工作,它们可以更改我的设置,所以我知道这不是问题。

I've already tried without the global declaration in the functions first but that didn't work and neither does it with the declaration. 我已经尝试过在函数中先没有全局声明,但这没有用,声明也没有。

Thanks for your help guys! 感谢您的帮助!

Sorry to say but you are using the % in way too many places 很抱歉,您在太多地方使用了%

Its use depends on where you are using the variable if it in an expression you do not use % around variables, in most other places you do, next thing is then to know when you're typing in something that accepts an expression, that take a little time to learn but here are two links that may help 它的使用取决于您在变量中使用变量的位置(如果在表达式中不使用%围绕变量),那么在大多数其他地方,接下来的事情就是知道您何时键入接受表达式的内容,需要一点时间来学习,但是这里有两个链接可能会有所帮助

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

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

Here is a little example of how it needs to look 这是它看起来的一个小例子

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)    
    }
}

Hope it helps 希望能帮助到你

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM