AutoHotkey: Replace abbreviated username with display name and date+time
How do I create a AutoHotkey-script which replaces my abbreviated network-username with my full display name including a timestamp?
andzi:
should be replaced by Andreas Zita (2011-04开发者_Python百科-08 09:56):
I want this to be a dynamic hotstring which can be applied to any username.
I think you can generate a ahk script and include it on the fly, because username is a variable. I have tried my own to build a very complex key mappings.
; This include() allows variable expression in the path parameter.
_include(path) {
local verf := 3, veri := 3
slash := instr(path, "\", false, 0)
if (slash != 0) {
base := substr(path, slash + 1)
} else {
base = %path%
}
filecreatedir %a_appdata%\.hotkey
inst = %a_appdata%\.hotkey\%base%
filegettime, verf, %path%
filegettime, veri, %inst%
if (verf != veri) {
ifexist, %path%
{
filecopy, %path%, %inst%, 1
if errorlevel {
msgbox can't include %path%: failed to copy to %inst%.
} else {
reload
}
} else {
filedelete, %inst%
if errorlevel {
msgbox failed to clean %inst%.
} else {
reload
}
}
}
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; User Extension {
userhotkey = %HOME%\etc\hotkey
_include(userhotkey)
#include *i %a_appdata%\.hotkey\hotkey
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;}
Here, function _include()
will generate a temporary file under %APPDATA%
, and then #include
it.
See: http://svn.bodz.net/core/trunk/etc/hotkey
P.S. This is just an example, in you case, you may generate the user hotkey as:
generate.bat:
@echo off
REM generate the ahk line to translate username to display name and datetime.
echo %USERNAME%:Your Name %DATETIME% >user.ahk
And in the main ahk script, execute generate.bat before #include it.
What you want is a hotstring! You can read the documentation in the help file to learn about hotstrings.
Specifically, try this code:
::andzi::
SendInput Andreas Zita (%A_YYYY%-%A_MM%-%A_DD% %A_Hour%:%A_Min%)
return
Run the script, type andzi, then press space.
精彩评论