开机脚本之——开心启动

这个开心启动界面我用了多年了,简单易用。


;-----------------------------------------
;
;  【开心启动界面】 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

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值