Sign in to follow this  
Followers 0
wreckage

Can I create script that displays date/time in a filed that is copyable?

3 posts in this topic

Hello.

 Is it possible to create a compiled application using AutoIT which displays the date and time in a user/configurable format that is able to be copied and then pasted anywhere?

Ideally, I'd like an application that pastes the current date and time into virtually any text field by way of a hot-key, but a manual copy/paste would be sufficient.

BTW, if anybody knows of a Windows 7 program which does this already, I'd be very grateful.

Thanks.

Share this post


Link to post
Share on other sites



Here is an example using hotkeys or a tray menu to send or paste a date time formated text.  Using a date/time format of your choosing.

#NoTrayIcon
#include <MsgBoxConstants.au3>
#include <Date.au3>

Global $sFormat = "dddd, MM-dd-yyyy hh:mm:ss tt"

HotKeySet("^!{ESC}", "Terminate")   ; Ctrl-Alt-Esc
HotKeySet("^!t", "_DateTime")       ; Ctrl-Alt-t (Send current date time.)
HotKeySet("^!f", "_FormatDateTime") ; Ctrl-Alt-f (Format date-time)

Opt("TrayMenuMode", 3) ; The default tray menu items will not be shown and items are not checked when selected. These are options 1 and 2 for TrayMenuMode.


Example()

Func Example()
    Local $iSettings = TrayCreateItem("Settings")

    Local $iAbout = TrayCreateItem("About")
    Local $iCopy = TrayCreateItem("Date Time to clipboard.")
    TrayCreateItem("") ; Create a separator line.

    Local $iExit = TrayCreateItem("Exit")

    TraySetState(1) ; Show the tray menu.

    While 1
        Switch TrayGetMsg()
            Case $iAbout ; Display a message box about the AutoIt version and installation path of the AutoIt executable.
                MsgBox($MB_SYSTEMMODAL, "", "Send Formated Date Time." & @CRLF & @CRLF & _
                        "Hot key: Ctrl-Alt-Esc (End this script)  " & @CRLF & _
                        "Hot key: Ctrl-Alt-t   (Send current date time.)" & @CRLF & _
                        "Hot key: Ctrl-Alt-f   (Format date-time)")

            Case $iSettings
                _FormatDateTime()

            Case $iCopy
                Local $tDate = _Date_Time_GetLocalTime()
                Local $SYSDate = _Date_Time_SystemTimeToDateTimeStr($tDate, 1)
                ClipPut(_DateFormat($SYSDate, $sFormat))

            Case $iExit ; Exit the loop.
                ExitLoop
        EndSwitch
    WEnd
EndFunc   ;==>Example

Func _FormatDateTime()
    Local $sFormatNew = InputBox("Date Time Format", "Existing format is:-" & @CRLF & $sFormat, $sFormat)
    If @error = 0 Then $sFormat = $sFormatNew

EndFunc   ;==>_FormatDateTime

Func _DateTime()
    Local $tDate = _Date_Time_GetLocalTime()
    Local $SYSDate = _Date_Time_SystemTimeToDateTimeStr($tDate, 1)
    Send(_DateFormat($SYSDate, $sFormat))
EndFunc   ;==>_DateTime

Func Terminate()
    Exit
EndFunc   ;==>Terminate


; Format date
; $sDate, input date in the format yyyy/MM/dd[ hh:mm:ss]
Func _DateFormat($sDate, $sFormat)
    $hGui = GUICreate("")
    $idDate = GUICtrlCreateDate($sDate, 10, 10)
    GUICtrlSendMsg($idDate, 0x1032, 0, $sFormat) ; or "dddd, MMMM d, yyyy hh:mm:ss tt"); or "hh:mm tt"
    $FormatedDate = GUICtrlRead($idDate)
    GUIDelete($hGui)
    Return $FormatedDate
EndFunc   ;==>_DateFormat

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0