Autohotkey AHK等待更多按热键循环浏览选项

Autohotkey AHK等待更多按热键循环浏览选项,autohotkey,Autohotkey,我正在与AHK一起使用COM控制Excel。当前脚本的想法是让脚本在每次单击热键时执行不同的选项来冻结excel工作表。在本例中,它是^f::(CTRL+f) 我的想法是,有一个5秒的计时器,等待同时按下,每次运行冻结功能。5秒后,脚本终止 我觉得这是一个相当简单的WaitKey实现,但我没有任何运气。我不知道如何使用ErrorLevel并用我的函数实现它 任何帮助都将不胜感激。我一直在看文档和其他帖子,但还没有弄清楚。我在下面写了一些伪代码来告诉你我想做什么 press_cycle :=0

我正在与AHK一起使用COM控制Excel。当前脚本的想法是让脚本在每次单击热键时执行不同的选项来冻结excel工作表。在本例中,它是^f::(CTRL+f)

我的想法是,有一个5秒的计时器,等待同时按下,每次运行冻结功能。5秒后,脚本终止

我觉得这是一个相当简单的WaitKey实现,但我没有任何运气。我不知道如何使用ErrorLevel并用我的函数实现它

任何帮助都将不胜感激。我一直在看文档和其他帖子,但还没有弄清楚。我在下面写了一些伪代码来告诉你我想做什么

press_cycle :=0

;; while KeyWait timer hasn't run out:
;;     wait for additional presses of hotkey
;;     if press 
;;         reset 5 sec timer
;;         run cycle_freezing() again 

cycle_freezing(){
    if (press_cycle = 3){
        MsgBox, "unfreezing"
        xl.Application.ActiveWindow.FreezePanes := False
        press_cycle := 0
    }
    if (press_cycle = 2){ ;; freeze header and selected column
        MsgBox, "freezing header and selected"
        ;XL_Freeze(xl,Row:=header_row,Col:=column)
        press_cycle := 3
    }
    if (press_cycle = 1){ ;; freeze header and first column
        MsgBox, "freezing header and first col"
        ;XL_Freeze(xl,Row:=header_row,Col:="B")
        press_cycle := 2
    }
    if (press_cycle = 0){ ;; freeze header
        MsgBox, "freezing header"
        XL_Freeze(xl,Row:=header_row,Col:="A")
        press_cycle := 1
    }
}
;***********************Freeze Panes********************************.
;~ XL_Freeze(XL,Row:="1",Col:="B") ;Col A will not include cols which is default so leave out if unwanted
;***********************Freeze Panes in Excel********************************.
XL_Freeze(xl,Row="",Col=""){
    xl.Application.ActiveWindow.FreezePanes := False ;unfreeze in case already frozen
    IfEqual,row,,return ;if no row value passed row;  turn off freeze panes
    xl.Application.ActiveSheet.Range(Col . Row+1).Select ;; Helps it work more intuitivly 
                                                         ;; 1 includes 1 not start at zero
    xl.Application.ActiveWindow.FreezePanes := True
}

这就是你想要的,但我不确定终止脚本是否意味着终止脚本?我觉得这听起来不明智

press_count := 0
^f::
    if(!press_count) ;zero evaluates to false
        ToolTip, % "Action that should happen after the 1st press"
    else if (press_count = 1)
        ToolTip, % "Action that should happen after the 2nd press"
    else if (press_count = 2)
        ToolTip, % "Action that should happen after the 3rd press"
    else
        ToolTip, % "Action that should happen after the 4th press"

    if(!press_count) ;if we're on the very first keypress
        SetTimer, ExitTimerCallback, -5000 ;set the timer, -5000 means it'll run ONCE after 5000ms
    else
        SetTimer, ExitTimerCallback ;otherwise reset the timer's period
    press_count++ ;increase by one
return

ExitTimerCallback:
    ExitApp
return
这是一个对我更有意义的版本,这可能就是你想要的

^f::
    if(A_TimeSincePriorHotkey < 5000)
        press_count++ ;increase by one if we're inside that 5sec window
    else
        press_count := 1 ;reset otherwise
    if(press_count = 1)
        ToolTip, % "Action that should happen after the 1st press"
    else if (press_count = 2)
        ToolTip, % "Action that should happen after the 2nd press"
    else if (press_count = 3)
        ToolTip, % "Action that should happen after the 3rd press"
    else
        ToolTip, % "Action that should happen after the 4th press"
return
^f::
如果(A_timesinceprior热键<5000)
按_count++;如果我们在5秒的窗口内,增加1
其他的
按计数:=1;否则重置
如果(按计数=1)
工具提示,%%“第一次按后应执行的操作”
否则如果(按计数=2)
工具提示,%%“第二次按下后应执行的操作”
否则如果(按计数=3)
工具提示,%%“第三次按后应执行的操作”
其他的
工具提示,%%“第四次按下后应执行的操作”
返回
我想对变量进行一些识别。
请记住,变量不只是针对<代码> ^ f>代码>热键,如果脚本更大,并且还触发其他热键,请考虑切换到如上面所示的计时器方法。只需重置
按_count
变量,而不是退出


你也没有说如果按下超过四次会发生什么,我会让你决定

这就是你想要的,但我不确定终止脚本是否真的意味着终止脚本?我觉得这听起来不明智

press_count := 0
^f::
    if(!press_count) ;zero evaluates to false
        ToolTip, % "Action that should happen after the 1st press"
    else if (press_count = 1)
        ToolTip, % "Action that should happen after the 2nd press"
    else if (press_count = 2)
        ToolTip, % "Action that should happen after the 3rd press"
    else
        ToolTip, % "Action that should happen after the 4th press"

    if(!press_count) ;if we're on the very first keypress
        SetTimer, ExitTimerCallback, -5000 ;set the timer, -5000 means it'll run ONCE after 5000ms
    else
        SetTimer, ExitTimerCallback ;otherwise reset the timer's period
    press_count++ ;increase by one
return

ExitTimerCallback:
    ExitApp
return
这是一个对我更有意义的版本,这可能就是你想要的

^f::
    if(A_TimeSincePriorHotkey < 5000)
        press_count++ ;increase by one if we're inside that 5sec window
    else
        press_count := 1 ;reset otherwise
    if(press_count = 1)
        ToolTip, % "Action that should happen after the 1st press"
    else if (press_count = 2)
        ToolTip, % "Action that should happen after the 2nd press"
    else if (press_count = 3)
        ToolTip, % "Action that should happen after the 3rd press"
    else
        ToolTip, % "Action that should happen after the 4th press"
return
^f::
如果(A_timesinceprior热键<5000)
按_count++;如果我们在5秒的窗口内,增加1
其他的
按计数:=1;否则重置
如果(按计数=1)
工具提示,%%“第一次按后应执行的操作”
否则如果(按计数=2)
工具提示,%%“第二次按下后应执行的操作”
否则如果(按计数=3)
工具提示,%%“第三次按后应执行的操作”
其他的
工具提示,%%“第四次按下后应执行的操作”
返回
我想对变量进行一些识别。
请记住,变量不只是针对<代码> ^ f>代码>热键,如果脚本更大,并且还触发其他热键,请考虑切换到如上面所示的计时器方法。只需重置
按_count
变量,而不是退出

你也没有说如果按下超过四次会发生什么,我会让你决定