Print current date and time in different formats depending on how many times the same hotkey is pressed

Post your working scripts, libraries and tools for AHK v1.1 and older
a0l0e0x000
Posts: 14
Joined: 26 Dec 2020, 08:27

Print current date and time in different formats depending on how many times the same hotkey is pressed

Post by a0l0e0x000 » 23 May 2021, 09:09

Press once you get: 23. 5. 2021
Press twice you get: 23/5/2021
Press 3 times you get: 16:06:28 23/5/2021
Script resets after 5 seconds.
Feel free to change or add time formats as well as change the F15 hotkey (CHANGE ALL "F15" IN THE SCRIPT FOR IT TO WORK) ;)

Code: Select all

F15::
SendMode Input
Hotkey, F15, , T3 ;3 threads, increase if more presses are added
FormatTime, CurrentDateTime,T8, d. M. yyyy ; ;T8 sets 24h time format, if American please switch to the superior 24h standard ;)
N_of_presses++
if N_of_presses = 1
{
  SendInput %CurrentDateTime%
}
if N_of_presses = 2
{
  date_dot = %CurrentDateTime%
  StringLen, date_dot_length, date_dot
  send, {backspace %date_dot_length%}
  FormatTime, CurrentDateTime,T8, d/M/yyyy
  send, %CurrentDateTime%
}
if N_of_presses = 3
{
  date_dot = %CurrentDateTime%
  StringLen, date_dot_length, date_dot
  send, {backspace %date_dot_length%}
  FormatTime, CurrentDateTime,T8, hh:mm:ss d/M/yyyy
  send, %CurrentDateTime%
}
sleep, 5000 ;time before script resets
N_of_presses = 0
return

Return to “Scripts and Functions (v1)”