AutoHotKey 例程(自用-高手勿噴)

AutoHotkey 是簡易而功能強大的熱鍵腳本語言。使用者可將鍵盤、鼠標甚至遊戲搖桿的移動和點擊動作記錄下來。

下面是博主經過近一年的使用經歷,工作之餘優化總結自用的腳本代碼,小白取用,大神輕噴!

;字符串替換

:*:f163::(郵箱)
:*:120::(身份證號)
:*:189::(手機號)
:O:tyl::(姓名)

:*:   ::{space}{space}{space}{space}{space}{space}{space}{space}
:O:ks::kernel skills:

;IP相關
:*:1112::192.168.1.201
:*:p1112::ping 192.168.1.2 -t {enter}

;Microsoft Office
do_office_invoke(exe)
{
    if (A_ComputerName = "Work-PC Name")
        run "D:\Microsoft Office\Office15\%exe%"
    else
        run "D:\office 2016\Office16\%exe%"
}

^!e:: do_office_invoke("EXCEL.EXE")
^!w:: do_office_invoke("WINWORD.EXE")
^!p:: do_office_invoke("POWERPNT.EXE")
;^!o:: do_office_invoke("ONENOTE.EXE")        ; for OnetasticInstaller
^!v:: do_office_invoke("VISIO.EXE")

;軟件快速打開
do_normal_invoke(exe)
{
    if (A_ComputerName = "Work-PC Name")
        run "E:\NS-SYN\Work-PC\Software shortcut\%exe%.lnk"
    else if (A_ComputerName = "Home-PC Name")
        run "E:\NS-SYN\Home-PC\Software shortcut\%exe%.lnk"
    else
        SendInput Unknown PC.
}

^!c::do_normal_invoke("win32calc.exe")
#n::do_normal_invoke("notepad++.exe")
!q::do_normal_invoke("QTranslate.exe")
#c::Run cmd

~/::
Input, UserInput, V T2 C, , /ns,/xm,/snip,/seer,/fdm,/tv,/netmail,/wsk,/kp,/netmusic,/ls,/si,/ahk,/ditto,/svn,/sc,/mstsc,/date,/time,/tima,/wb,/bt,/tm,/dm,/sys,/csdn,/gfs,/bdy,/bc,/fb,/le,/pp,/wx,/yk,/od,/ie,/md,/py,/qt,/xh,/gd,/gc
if (ErrorLevel != "Match")
    return
if (ErrorLevel = "NewInput")
    return

StringLength := StrLen(UserInput) + 1
SendInput {BackSpace %StringLength%}

;;; Work&Home-PC Common ;;;
if (UserInput = "/ns")
    do_normal_invoke("Nutstore.exe")
else if (UserInput = "/xm")
    do_normal_invoke("XMind.exe")
else if (UserInput = "/snip")
    do_normal_invoke("Snipaste.exe")
else if (UserInput = "/seer")
    do_normal_invoke("Seer.exe")
else if (UserInput = "/fdm")
    do_normal_invoke("fdm.exe")
else if (UserInput = "/tv")
    do_normal_invoke("TeamViewer.exe")
else if (UserInput = "/netmail")
    do_normal_invoke("mailmaster.exe")
else if (UserInput = "/wsk")
    do_normal_invoke("Wireshark.exe")
else if (UserInput = "/kp")
    do_normal_invoke("KeePass.exe")
else if (UserInput = "/netmusic")
    do_normal_invoke("cloudmusic.exe")
else if (UserInput = "/ls")
    do_normal_invoke("Listary.exe")
else if (UserInput = "/si")
    do_normal_invoke("sourceinsight4.exe")
else if (UserInput = "/bc")
    do_normal_invoke("BCompare.exe")
else if (UserInput = "/ahk")
    do_normal_invoke("AutoHotkey_cn.chm")
else if (UserInput = "/ditto")
    do_normal_invoke("Ditto.exe")
else if (UserInput = "/pp")
    do_normal_invoke("PotPlayerMini64.exe")
else if (UserInput = "/od")
    do_normal_invoke("OneDrive.exe")
else if (UserInput = "/tm")                ;打開任務管理器 
    do_normal_invoke("taskmgr.exe")
else if (UserInput = "/dm")                ;打開設備管理器
    do_normal_invoke("devmgmt.msc")
else if (UserInput = "/sys")               ;打開系統屬性
    do_normal_invoke("msinfo32.exe")
else if (UserInput = "/md")
    do_normal_invoke("MarkdownPad 2")
else if (UserInput = "/py")
    do_normal_invoke("IDLE (Python 3.6 64-bit)")
else if (UserInput = "/qt")
    do_normal_invoke("QTranslate.exe")
else if (UserInput = "/gd")
    do_normal_invoke("GitHub Desktop")
    
;;; SendInput & Run ;;;
else if (UserInput = "/date")
    SendInput %A_YYYY%/%A_MM%/%A_DD%
else if (UserInput = "/time")
    SendInput %A_YYYY%/%A_MM%/%A_DD% %A_Hour%:%A_Min%:%A_Sec%
else if (UserInput = "/tima")
    SendInput %A_YYYY%%A_MM%%A_DD%-%A_Hour%%A_Min%%A_Sec%
else if (UserInput = "/gc")
    SendInput [Change record]{enter}{enter}{enter}[Submitter]{enter}fhqfghgdx{enter}{enter}[Submission date]{enter}%A_YYYY%-%A_MM%-%A_DD%
else if (UserInput = "/csdn")
    Run http://www.csdn.net/
else if (UserInput = "/gfs")
    Run http://gufenso.huizhanzhang.com/

;;; Work & Home-PC Difference ;;;
;;; Only in Work-PC ;;;
else if (UserInput = "/svn")
    do_normal_invoke("TortoiseSVN Repository Browser")
else if (UserInput = "/mstsc")        ;打開遠程連接
    do_normal_invoke("mstsc.exe")
else if (UserInput = "/xh")
    do_normal_invoke("Xshell.exe")
else if (UserInput = "/ie") {
    do_normal_invoke("Internet Explorer")
;        Sleep,2500
;        SendInput 04719{tab}loNG2263{enter}
    }

;;; Only in Home-PC ;;;
if (UserInput = "/bdy")
    do_normal_invoke("baidunetdisk.exe")
else if (UserInput = "/fb")
    do_normal_invoke("foobar2000.exe")
else if (UserInput = "/le")
    do_normal_invoke("LeTVLoader.exe")
else if (UserInput = "/wx")
    do_normal_invoke("WeChat.exe")
else if (UserInput = "/yk")
    do_normal_invoke("YoukuDesktop.exe")
else if (A_ComputerName = "Work-PC Name")
{
    if (UserInput = "/sc")
        SendInput [修改記錄]{enter}{enter}{enter}[提交人]{enter}NAME{enter}{enter}[提交日期]{enter}%A_YYYY%-%A_MM%-%A_DD%
    else if (UserInput = "/bt")
        SendInput 周工作總結-NAME-%A_YYYY%-%A_MM%-%A_DD%
    else if (UserInput = "/wb")
        SendInput %A_YYYY%-%A_MM%-%A_DD% 日總結:{enter}1.{space}
}
else if (A_ComputerName = "Home-PC Name")
{
    ; Just for SendInput or Run in Home-PC
}
return

;快速搜索
;一鍵百度
!b::
Run http://www.baidu.com/s?wd=%clipboard%
return

;一鍵淘寶
!t::
Run http://s.taobao.com/search?q=%clipboard%
return

;一鍵京東
!j::
Run http://search.jd.com/Search?keyword=%clipboard%
return

;一鍵谷歌
!g::
run https://d.ggkai.men/search?ie=utf-8&shb=1&q=%clipboard%
return

;一鍵Bing
!+b::
run https://www.bing.com/search?q=%clipboard%&qs=n&form=QBLH&sp=-1&pq=%clipboard%&sc=8-7&sk=&cvid=F692AEB409BF4B9BBC088D606ABFC00E
return

下列內容可忽略之~

以下內容爲筆者測試和學習的其他知識點,暫時還沒時間實際用起來,希望有大神指點一二!

;; Test and Learning. ;;

::ts::
MsgBox, 4, , Would you like to open baidu?
IfMsgBox, No
    Return
Run http://www.baidu.com
MsgBox You pressed YES.
return

;$F3::
while(getkeystate("F3","p"))
{
    MsgBox, You had press F3 to active 'devmgmt.msc'.{enter}
    do_normal_invoke("devmgmt.msc")
    click
}

return

;$F2::
loop
{
    SendInput Just For Test .{enter}
    getkeystate("F2","p")
        break
    click
}
return

;:://var::
MyVar1 = 123
MyVar2 = my string

If MyVar2 = my string
{
MsgBox MyVar2 contains the string “my string”.
}
If MyVar1 >= 100
{
MsgBox MyVar1 contains %MyVar1%, which is a number greater than or equal to 100.
}
return

:://tst::
RunWait Notepad
MsgBox The user has finished (Notepad has been closed).
return

:*:]d::
FormatTime, CurrentDateTime,, yyyy/MM/dd HH:mm:ss
SendInput %CurrentDateTime%
return

GitHub 目錄:https://github.com/fhqfghgdx/AutoHotKey

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章