0
votes

I want to accomplish an apparently easy task with autohotkey: when certain hotstring is detected, then show a tooltip (in this case, with the current date). While the tooltip is displayed I want to react to UP and DOWN key-presses showing the next and previous item on an array respectively. Then when the Enter key is pressed I want to confirm the "selection" and paste that tooltip text. Here is the current code, which looks too big for a task that is so simple.

   ; ------------------------ 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
}
2

2 Answers

1
votes
::#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
1
votes
::#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