【问题标题】:autohotkey looping tooltip and confirm selection with enter自动热键循环工具提示并使用 enter 确认选择
【发布时间】:2015-02-20 23:51:47
【问题描述】:

我想用自动热键完成一项看似简单的任务:当检测到某个热字串时,显示一个工具提示(在这种情况下,显示当前日期)。显示工具提示时,我想对 UP 和 DOWN 按键做出反应,分别显示数组上的下一个和上一个项目。然后,当按下 Enter 键时,我想确认“选择”并粘贴该工具提示文本。这是当前的代码,对于如此简单的任务来说看起来太大了。

   ; ------------------------ Date tooltip

::#curdate::
  EnteringDate := True
  DateSeparator := [".","/","-"]
  SelectedSep := 1
  GoSub, ShowToolTip
return 

ShowToolTip:
  Sep := DateSeparator[SelectedSep]
  FormatTime, Time,, dd%Sep%MM%Sep%yyyy ; dd MM yyyy is day month year
  ToolTip, %Time%
return

#If EnteringDate

Up::
SelectedSep := cycle(SelectedSep,DateSeparator.MaxIndex(),1)
GoSub, ShowToolTip
return

Down::
SelectedSep := cycle(SelectedSep,DateSeparator.MaxIndex(),-1)
GoSub, ShowToolTip
return

Enter::
EnteringDate := False
SendInput, %Time%
ToolTip ; Clear the tool tip
return

#If ; end entering date

cycle(value,maxValue,increment:=1){
 value += increment
 if value not between 1 and %maxValue%
    value := increment<0 ? maxValue : 1
 return value
}

【问题讨论】:

    标签: autohotkey


    【解决方案1】:
    ::#curdate::
        i:=0,DateSep:= [".","/","-"],EnteringDate:=1
      return
    #If EnteringDate
    Up::
        ToolTip
        ,% DateSep[i:=i<DateSep.MaxIndex()?++i:1]
      return
    Down::
        ToolTip
        ,% DateSep[i:=i>1?--i:DateSep.MaxIndex()]
      return
    Enter::
        EnteringDate:=0,Sep := DateSep[i]
        FormatTime, Time,, dd%Sep%MM%Sep%yyyy 
        SendInput, %Time%
        ToolTip
      return
    #If
    Esc::ExitApp
    

    【讨论】:

    • 这几乎是完美的,除了我想在每个工具提示上显示格式化的日期。我知道 AHK 上的三元运算符,但我不知道你可以在数组中使用它(我在 JS 中以这种方式使用它,但这似乎是一种非常有限的语言)。 % 运算符是干什么用的?我认为它“激活”了某种模式,但我不确定。
    • ;设置变量传统=字符串,表达式:=“字符串”;获取变量 MsgBox,%traditional% , MsgBox,% 表达式
    【解决方案2】:
    ::#curdate::
        i:=0,DateSep:= [".","/","-"],EnteringDate:=1
        SendLevel,1
        Send,{up}
      return
    #If EnteringDate
    Up::
        DateSep[i:=i<DateSep.MaxIndex()?++i:1]
        Sep:=DateSep[i]
        FormatTime, Time,, dd%Sep%MM%Sep%yyyy
        ToolTip,% Time
      return
    Down::
        DateSep[i:=i>1?--i:DateSep.MaxIndex()]
        Sep:=DateSep[i]
        FormatTime, Time,,dd%Sep%MM%Sep%yyyy
        ToolTip,% Time
      return
    Enter::
        EnteringDate:=0
        SendInput, % Time
        ToolTip
      return
    #If
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-01-31
      • 1970-01-01
      • 2018-11-16
      • 1970-01-01
      • 1970-01-01
      • 2022-11-27
      • 1970-01-01
      相关资源
      最近更新 更多