Advertisement
robertmarkbram

Adaptation of Generic Date Picker Version 2 by Paul Moss

Mar 7th, 2013
643
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; Generic Date Picker Version 2
  2. ; Created by: Paul Moss
  3. ; October 18, 2011
  4. ; Use at you own risk
  5. ; http://www.autohotkey.com/board/topic/72540-generic-date-picker-google-docs-forms-anywhere-everwh/
  6.  
  7. ; Modified by Robert Mark Bram to run as a persistent script. Run the AHK file and the script will stay in memory. Press control+shift+d to access the date picker.
  8. ; http://robertmarkbramprogrammer.blogspot.com.au/2011/02/insert-date-into-any-program-using.html#comment-821926742
  9. #SingleInstance Force
  10. #NoEnv  ; Recommended for performance and compatibility w future AutoHotkey releases.
  11.  
  12. +^D:: runDatePicker() ;; Command to run date picker with control+shift+D
  13.  
  14. runDatePicker() {
  15.     global ActivePID
  16.    WinGet, ActivePID, PID, A
  17.  
  18.    gblFormats := "MM/dd/yyyy`nMM/dd/yyyy hh:mm tt`nMM/dd/yyyy hh:mm:ss tt`ndd/MM/yyyy`ndd/MM/yyyy hh:mm tt`ndd/MM/yyyy hh:mm:ss tt`nMMMM d, yyyy`nMMMM d, yyyy hh:mm tt`nMMMM d, yyyy hh:mm:ss tt`ndddd, MMMM d, yyyy`ndddd, MMMM d, yyyy hh:mm tt`ndddd, MMMM d, yyyy hh:mm:ss tt`nyyyy, d-MMMM, (dddd)`nyyyy.MM.dd `nyyyy-MM-dd`nyyyyMMdd`nyyyy.MM.dd_hh.mm`nyyyy-MM-dd_hh-mm`nyyyyMMdd_hhmm"
  19.    IfNotExist, %A_ScriptDir%\DatePicker.ini
  20.    {
  21.         IniWrite, %gblFormats%, %A_ScriptDir%\DatePicker.ini, DateFormats
  22.    }
  23.    IniRead, DpFormats, %A_ScriptDir%\DatePicker.ini, DateFormats
  24.  
  25.    Gui, Add, Text, x12 y10 w210 h20 , Choose date
  26.    Gui, Add, DateTime, x12 y30 w210 h20 gDate_time vDt, LongDate
  27.    Gui, Add, Text, x12 y60 w210 h20 , Choose time
  28.    Gui, Add, DateTime, x12 y80 w210 h20 gMyTime vMyt, time
  29.    Gui, Add, Button, x132 y160 w90 h30 gBtnCancel , Cancel
  30.    Gui, Add, Button, x42 y160 w90 h30 Default gBtnOK, OK
  31.    Gui, Add, Text, x242 y10 w220 h20 , Select output format
  32.    Gui, Add, ListBox, x242 y30 w220 h170 -Wrap +HScroll gListboxControl vLstItem hWndLB1, |
  33.  
  34.    Gui, Show, w476 h202, Date Selector
  35.  
  36.    FormatListDisplay(A_Now, DpFormats)
  37. }
  38.  
  39.  
  40.  
  41. ListboxControl:
  42. return
  43.  
  44. BtnCancel:
  45. GuiEscape:
  46. GuiClose:
  47.    Gui Destroy
  48. Return  ; All of the above labels will do this.
  49.  
  50.  
  51. BtnOK:
  52.     Gui, Submit, Hide
  53.     if (!LstItem){
  54.         MsgBox, 64, No Date Format Selected, You have not selected a date format!`nPlease select a date format from the list and try again.
  55.         gui, Show
  56.         return
  57.     }
  58.     InsertDate(LstItem)
  59.    Gui Destroy
  60. return
  61.  
  62. Date_time:
  63.     Gui, Submit, Nohide
  64.     FormatListDisplay(CombineDateTime(Dt,Myt), DpFormats)
  65. return
  66.  
  67. MyTime:
  68.     Gui, Submit, Nohide
  69.     FormatListDisplay(CombineDateTime(Dt,Myt), DpFormats)
  70. return
  71.  
  72.  
  73. InsertDate(sDate){
  74.     global ActivePID
  75.  
  76.     IfWinNotExist , ahk_pid %ActivePID%
  77.     {
  78.         MsgBox, 262160, Window not Found, Date Picker is unable to find the active window. Please try again.
  79.         return
  80.     }
  81.  
  82.     IfWinNotActive, ahk_pid %ActivePID% , , WinActivate, ahk_pid %ActivePID%,
  83.  
  84.     sleep 500
  85.  
  86.     SendInput %sDate%
  87. }
  88.  
  89. CombineDateTime(varDate, varTime){
  90.     varymd := SubStr(varDate,1,8)
  91.     varhms := Substr(varTime,9)
  92.     varNewDate := varymd . varhms
  93.     return varNewDate
  94.  
  95. }
  96.  
  97. FormatListDisplay(varDate,varFormats){
  98.  
  99.     local CurrentDateTime, lstItems
  100.  
  101.     Loop, Parse, varFormats, `n, %A_Space%%A_Tab% ; Loop the formats and ignore any spaces and tabs
  102.     {
  103.         FormatTime, CurrentDateTime, %varDate%, %A_LoopField%
  104.         if (A_Index = 1){
  105.             lstItems := CurrentDateTime
  106.         }
  107.         else{
  108.             lstItems := lstItems . "|" . CurrentDateTime
  109.         }
  110.     }
  111.     GuiControl, -Redraw, LstItem
  112.     GuiControl,, LstItem, |
  113.     GuiControl,, LstItem, %lstItems%
  114.     GuiControl, +Redraw, LstItem
  115.  
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement