Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; Generic Date Picker Version 2
- ; Created by: Paul Moss
- ; October 18, 2011
- ; Use at you own risk
- ; http://www.autohotkey.com/board/topic/72540-generic-date-picker-google-docs-forms-anywhere-everwh/
- ; 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.
- ; http://robertmarkbramprogrammer.blogspot.com.au/2011/02/insert-date-into-any-program-using.html#comment-821926742
- #SingleInstance Force
- #NoEnv ; Recommended for performance and compatibility w future AutoHotkey releases.
- +^D:: runDatePicker() ;; Command to run date picker with control+shift+D
- runDatePicker() {
- global ActivePID
- WinGet, ActivePID, PID, A
- 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"
- IfNotExist, %A_ScriptDir%\DatePicker.ini
- {
- IniWrite, %gblFormats%, %A_ScriptDir%\DatePicker.ini, DateFormats
- }
- IniRead, DpFormats, %A_ScriptDir%\DatePicker.ini, DateFormats
- Gui, Add, Text, x12 y10 w210 h20 , Choose date
- Gui, Add, DateTime, x12 y30 w210 h20 gDate_time vDt, LongDate
- Gui, Add, Text, x12 y60 w210 h20 , Choose time
- Gui, Add, DateTime, x12 y80 w210 h20 gMyTime vMyt, time
- Gui, Add, Button, x132 y160 w90 h30 gBtnCancel , Cancel
- Gui, Add, Button, x42 y160 w90 h30 Default gBtnOK, OK
- Gui, Add, Text, x242 y10 w220 h20 , Select output format
- Gui, Add, ListBox, x242 y30 w220 h170 -Wrap +HScroll gListboxControl vLstItem hWndLB1, |
- Gui, Show, w476 h202, Date Selector
- FormatListDisplay(A_Now, DpFormats)
- }
- ListboxControl:
- return
- BtnCancel:
- GuiEscape:
- GuiClose:
- Gui Destroy
- Return ; All of the above labels will do this.
- BtnOK:
- Gui, Submit, Hide
- if (!LstItem){
- MsgBox, 64, No Date Format Selected, You have not selected a date format!`nPlease select a date format from the list and try again.
- gui, Show
- return
- }
- InsertDate(LstItem)
- Gui Destroy
- return
- Date_time:
- Gui, Submit, Nohide
- FormatListDisplay(CombineDateTime(Dt,Myt), DpFormats)
- return
- MyTime:
- Gui, Submit, Nohide
- FormatListDisplay(CombineDateTime(Dt,Myt), DpFormats)
- return
- InsertDate(sDate){
- global ActivePID
- IfWinNotExist , ahk_pid %ActivePID%
- {
- MsgBox, 262160, Window not Found, Date Picker is unable to find the active window. Please try again.
- return
- }
- IfWinNotActive, ahk_pid %ActivePID% , , WinActivate, ahk_pid %ActivePID%,
- sleep 500
- SendInput %sDate%
- }
- CombineDateTime(varDate, varTime){
- varymd := SubStr(varDate,1,8)
- varhms := Substr(varTime,9)
- varNewDate := varymd . varhms
- return varNewDate
- }
- FormatListDisplay(varDate,varFormats){
- local CurrentDateTime, lstItems
- Loop, Parse, varFormats, `n, %A_Space%%A_Tab% ; Loop the formats and ignore any spaces and tabs
- {
- FormatTime, CurrentDateTime, %varDate%, %A_LoopField%
- if (A_Index = 1){
- lstItems := CurrentDateTime
- }
- else{
- lstItems := lstItems . "|" . CurrentDateTime
- }
- }
- GuiControl, -Redraw, LstItem
- GuiControl,, LstItem, |
- GuiControl,, LstItem, %lstItems%
- GuiControl, +Redraw, LstItem
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement