開機腳本之——開心啓動

這個開心啓動界面我用了多年了,簡單易用。


;-----------------------------------------
;
;  【開心啓動界面】 v2.0  By FeiYue
;
;  ☆ 特色:右鍵雙擊啓動,易用易添加,飛速啓動酷狗
;
;  ☆ 點擊“腳本編輯”可以方便地自主添加功能和刪除按鈕
;
;-----------------------------------------

~*RButton::    ;-- 【鼠標右鍵雙擊】顯示“開心啓動界面”
Critical
CoordMode, Mouse
MouseGetPos, x, y
now_time:=A_TickCount
if (now_time-last_time<200)
  or (now_time-last_time>500)
  or Abs(x-oldx)+Abs(y-oldy)>5
{
  last_time:=now_time, oldx:=x, oldy:=y
  return
} else last_time:=0

;------ 消除多餘的右鍵菜單 ------
SetTimer, Close_Menu, -500
Close_Menu()
Close_Menu() {
  MouseGetPos, x, y
  DetectHiddenWindows, Off
  WinGet, list, List, ahk_class #32768
  Loop, %list% {
    id:=list%A_Index%
    WinGetPos, x1, y1, w, h, ahk_id %id%
    x2:=x1+w-1, y2:=y1+h-1
    if Abs(x-x1)+Abs(y-y1)<10 or Abs(x-x1)+Abs(y-y2)<10
    or Abs(x-x2)+Abs(y-y1)<10 or Abs(x-x2)+Abs(y-y2)<10
      ControlSend,, {Esc}, ahk_id %id%
  }
}

;------ 首次啓動先生成界面 ------
Gui, HappyRun: +LastFoundExist
IfWinNotExist
{
  Gui, HappyRun: New
  Gui, +LastFound +AlwaysOnTop +Owner -MinimizeBox
  Gui, Margin, 20, 20
  Gui, Font, s12 bold
  Gui, Color, CCFFAA
  Gui, Add, Button, w510 gAdd_New, 快 速 新 增 軟 件

  ;---- 計算選項卡的高度和寬度 ----
  ;  按鈕高度:(字體大小+1)*7//3 ==> 30
  ;  選項卡總高度:(按鈕高度+20)*(5+1)  ==> 300
  ;  按鈕限寬150,選項卡總寬度:150*3+15*4 ==> 510
  ;---- 每頁放15個按鈕,四頁不夠可以再加 ----

  Gui, Add, Tab2, w510 h300 vMyTab border, 第一頁|第二頁|第三頁|第四頁
  if A_IsCompiled
  {
    s:="腳本重啓|腳本編輯|……"    ;-- 若要編譯,請自己生成標籤列表
  }
  else
  {
    FileRead, fs, %A_ScriptFullPath%
    s:=r:="", i:=1
    While i:=RegExMatch(fs,"\n\s*\[(\S+)\]:\s*\n",r,i+StrLen(r))
      s.=(s="") ? r1 : "|" . r1
    fs:=""
  }
  Loop, Parse, s, |
  {
    i:=A_Index, j:=Mod(i,3)=1 ? "xm+15 y+20" : "xp+165"
    if Mod(i,15)=1
      Gui, Tab, % i//15+1
    Gui, Add, Button, %j% r1 gAll_Run Hwndcid, %A_LoopField%
    GuiControlGet, p, Pos, %cid%
    if pW>150    ;-- 限制每個按鈕的寬度最多爲150
    {
      GuiControl, +Left, %cid%
      GuiControl, Move, %cid%, w150
    }
  }
  s=
  Gui, Tab
  Gui, Show, Hide AutoSize, (^_^)開心啓動!--<<@

  ;----- 獲取“酷狗音樂”按鈕的位置 ------
  SetTitleMatchMode, 2
  ControlGetPos, x1, y1, w, h, 酷狗音樂
  kugou_x:=x1+w//2, kugou_y:=y1+h//2
}

;-- 以“酷狗音樂”按鈕爲中心顯示,直接點擊鼠標左鍵就運行
Gui, HappyRun: Default
GuiControl, Choose, MyTab, 1
GuiControl, Focus, 酷狗音樂     ;-- 方便按空格運行
GuiControl, +Default, 酷狗音樂  ;-- 方便按確定運行
x:=Round(x-kugou_x), y:=Round(y-kugou_y)
Gui, Show, x%x% y%y%
SetTimer, HappyRun_NA, 100
return

;-- 當界面窗口不激活就自動關閉
HappyRun_NA:
ListLines, Off
Gui, HappyRun: +LastFoundExist
IfWinActive
{
  if (!HappyRun_Active)
    HappyRun_Active:=1
}
else
{
  if (HappyRun_Active)
  {
    HappyRun_Active:=0
    WinHide
    SetTimer,, Off
  }
}
return

;-- 點擊“新增軟件”可以輕易擴展界面
Add_New:
Gui, Hide
if A_IsCompiled
{
  MsgBox, 4096,, 已編譯程序不能新增軟件!, 1
  return
}
FileSelectFile, f
IfNotExist, %f%
  return
SplitPath, f,,,, name
name:=r:=RegExReplace(name,"\s+","_")
While IsLabel("[" name "]")
  name:=r . A_Index
s=`n`n[%name%]:`nRunApp("%f%")`nreturn`n
FileAppend, %s%, %A_ScriptFullPath%
Sleep, 500
Reload
return

All_Run:
k:=Trim(A_GuiControl)
if k not in 增大音量,減小音量
{
  WinHide
  WinWaitNotActive
}
k=[%k%]
if IsLabel(k)
  Goto, %k%
return

Tip(s:="") {
  SetTimer, %A_ThisFunc%, % s="" ? "Off" : -2000
  ToolTip, %s%
}

RunApp(file, show=1) {
  SplitPath, file,, dir
  dir:=FileExist(dir "\") ? dir : ""
  s:=show ? "" : "Hide"
  Run, "%file%", %dir%, UseErrorLevel %s%
}

;==== 下面的按鈕名稱及功能都可以修改 ====


[腳本重啓]:
SplitPath, A_ScriptName,,,, name
IfWinExist, %name% ahk_class Notepad
{
  PostMessage, 0x111, 3
  Sleep, 500
}
Reload
return


[腳本編輯]:
if !A_IsCompiled
  Run, notepad.exe "%A_ScriptFullPath%"
return


[查看運行]:
ListLines
return


[酷狗上一首]:
酷狗音樂("上一首")
return

酷狗音樂(命令)  ;-- 可靠性高的方法可以使用ACC
{
    SetTitleMatchMode, 2
    DetectHiddenWindows, On
    WinGet, List, List, 酷狗音樂 ahk_exe KuGou.exe
    IfLess, List, 1, return
    Loop, % List
    {
        id:=List%A_Index%
        WinGetPos,,, w, h, ahk_id %id%
        if (A_Index=1 or w*h>max)
            okid:=id, max:=w*h
    }
    ;-- 這種方法不支持最小化
    WinGetPos,,, w, h, ahk_id %okid%
    x:=InStr(命令,"上一首") ? w//2-50 : w//2+50, y:=h-35
    SetControlDelay, -1
    ControlClick, x%x% y%y%, ahk_id %okid%,,,, NA
}


[酷狗音樂]:
IfWinActive, ahk_exe KuGou.exe
{
  ;-- 酷狗在顯示和隱藏之間切換
  WinClose
}
else
{
  ;-- 酷狗程序的路徑需要重新設定
  RunApp("W:\影音軟件\酷狗音樂\SW_PlayPlay.exe")
}
return


[酷狗下一首]:
酷狗音樂("下一首")
return


[增大音量]:
SoundSet, +5
SoundGet, i
Tip("當前音量:" Round(i))
return


[切換靜音]:
SoundSet, +1,, mute
return


[減小音量]:
SoundSet, -5
SoundGet, i
Tip("當前音量:" Round(i))
return


[AHK幫助]:
path:=A_IsCompiled ? A_ScriptFullPath:A_AhkPath
SplitPath, path,, dir
Run, "%dir%\AutoHotkey.chm"
SetTitleMatchMode, 2
WinWait, 中文幫助,, 5
if !ErrorLevel
  WinMove, 0, 0
return


[AHK目錄]:
dir:=A_IsCompiled ? A_ScriptDir : RegExReplace(A_AhkPath,"\\[^\\]*$")
Run, "%dir%\"
return


[AU3_Spy]:
oldx:=oldy:=""
While !WinExist("開心啓動 ahk_class AutoHotkeyGUI")
{
  Sleep, 100
  MouseGetPos, x, y, id, class
  if (oldx=x and oldy=y)
    Continue
  oldx:=x, oldy:=y
  WinGetTitle, tt, ahk_id %id%
  WinGetClass, tc, ahk_id %id%
  WinGetPos, winx, winy, w, h, ahk_id %id%
  winx:=x-winx, winy:=y-winy
  ToolTip
    , % "屏幕座標:" x "," y
    . "`n窗口座標:" winx "," winy
    . "`n窗口寬高:" w "," h
    . "`n窗口標題:" RegExReplace(tt,"\s*(\S[^\r\n]*)[\s\S]*","$1")
    . "`n窗口類名:" "ahk_class " tc
    . "`n控件類名:" class
}
ToolTip
return


[記事本]:
Run, notepad.exe
return


[彈出U盤]:
DetectHiddenWindows, Off
Run, %A_WinDir%\System32\control.exe hotplug.dll
WinWait, 安全刪除硬件,, 5
if ErrorLevel
  return
IfWinNotActive
{
  WinActivate
  WinWaitActive
}
BlockInput, SendAndMouse
ControlGet, i, Enabled,,Button2
if (i)
{
  ControlSend, SysTreeView321, {End}
  ControlSend, Button2, s
  WinWait, 停用硬件設備,, 5
  if !ErrorLevel
    ControlSend, Button1, {Enter}
}
BlockInput, Default
WinClose, 安全刪除硬件
return


[計算器]:
Run, calc.exe
return


[快速關機]:
MsgBox, 4100, 請確認, 你真的想關機嗎?
IfMsgBox, Yes
  Shutdown, 9
return


[開關光驅]:
Drive, Eject
if A_TimeSinceThisHotkey < 1000  ;-- 可能需要調整這個時間值
  Drive, Eject,, 1
return


[總在最前]:
Hotkey, $*LButton, _LButton_Off, On  ;-- 暫時屏蔽左鍵
SetTimer, Show_Tip, 30
KeyWait, LButton, D
KeyWait, LButton
MouseGetPos,,, id
WinSet, AlwaysOnTop,, ahk_id %id%
Hotkey, $*LButton, Off
SetTimer, Show_Tip, Off
ToolTip
_LButton_Off:
return
Show_Tip:
ListLines, Off
ToolTip, 請用鼠標左鍵點擊想設置`n[或取消]總在最前的窗口
return

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