menu

秋梦无痕

一场秋雨无梦痕,春夜清风冻煞人。冬来冷水寒似铁,夏至京北蟑满城。

Avatar

热键锁定系统

朋友说他的键盘上没有win键,所以锁定系统是件很麻烦的事情,虽然通过开始菜单可以操作,但毕竟还是不如Win+L快捷。前几天在网上闲逛,看到www.autohotkey.com,觉得挺有意思,就随手做了一个一键锁定系统的程序。需要的同学可以在这里(http://skydrive.live.com/)下载,默认热键是“PAUSE”。

源码如下:

;LockSystem.ahk
;Lock system by pressing a hotkey, default "PAUSE"
;cyifyr(@)gmail(.)com

#SingleInstance,Force

applicationname=LockSystem

Gosub,REG
Gosub,TRAYMENU
Return

HOTKEY:
;rundll32.exe user32.dll,LockWorkStation
DllCall("LockWorkStation", str, "user32")
Return

TRAYMENU:
Menu,Tray,NoStandard
Menu,Tray,DeleteAll
Menu,Tray,Add,设置,SETTINGS
Menu,Tray,Add,自动启动,TOGGLEAUTORUN
Menu,Tray,Add,退出,EXIT
Menu,Tray,Default,设置
If autorun
{
Menu,Tray,Check,自动启动
}
Return

SETTINGS:
HotKey,%hotkey%,Off
Gui,Destroy
Gui,Add,GroupBox,xm ym w220 h70,热键(&H)
Gui,Add,Hotkey,xp+10 yp+20 w200 vshotkey
StringReplace,current,hotkey,+,Shift +%A_Space%
StringReplace,current,current,^,Ctrl +%A_Space%
StringReplace,current,current,!,Alt +%A_Space%
Gui,Add,Text,,当前热键:%current%
Gui,Add,Button,xm y+20 w75 GSETTINGSOK,确定
Gui,Add,Button,x+5 w75 GSETTINGSCANCEL,取消
Gui,Show,,设置
Return

SETTINGSOK:
Gui,Submit
If shotkey<>
{
hotkey:=shotkey
HotKey,%hotkey%,HOTKEY
}
HotKey,%hotkey%,On
RegWrite, REG_SZ, HKEY_CURRENT_USER, Software\Microsoft\Windows\Shell, LockSystem, %hotkey%
Gui,Destroy
Return

SETTINGSCANCEL:
HotKey,%hotkey%,HOTKEY
HotKey,%hotkey%,On
Gui,Destroy
Return

; 这一部分自动启动是为了方便使用添加的,而且处理方式很简单,可能有人会不喜欢
TOGGLEAUTORUN:
If autorun
{
RegDelete, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Run, LockSystem
autorun:=0
Menu, Tray, Uncheck, 自动启动
}
Else
{
RegWrite, REG_SZ, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Run, LockSystem, C:\Windows\System32\LockSystem.exe
autorun:=1
Menu, Tray, Check, 自动启动
}
Return

REG:
IfNotExist,C:\WINDOWS\System32\LockSystem.exe
{
FileCopy,%A_ScriptFullPath%,C:\Windows\System32\LockSystem.exe,0
}
hotkey:="PAUSE" ; 默认热键
autorun:=0
path_autorun:=""
RegRead,hotkey,HKEY_CURRENT_USER,Software\Microsoft\Windows\Shell,LockSystem
RegRead,path_autorun,HKEY_CURRENT_USER,Software\Microsoft\Windows\CurrentVersion\Run,LockSystem
If path_autorun<>
{
autorun:=1
}
HotKey,%hotkey%,HOTKEY
HotKey,%hotkey%,On
Return

EXIT:
ExitApp

评论已关闭