⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.pas

📁 Windows的关闭显示器的设置时间好像最短是1分钟 而直接关显示器电源又怕伤显示器(是吗?:),于是写了这个程序
💻 PAS
字号:
unit Main;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, ComCtrls, Menus;

type
  TForm1 = class(TForm)
    Timer1: TTimer;
    Button1: TButton;
    Edit1: TEdit;
    HotKey1: THotKey;
    procedure Button1Click(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure HotKey1Change(Sender: TObject);
    procedure HotKeyDown(var Msg: Tmessage); message WM_HOTKEY;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }
  public
    { Public declarations }
    counter: Integer;
    HotKeyId: Integer;
    Key: word;
    ShiftState0: TShiftState;
    ShiftState: Cardinal;
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  if Timer1.Enabled = True then
  begin
    Timer1.Enabled := False;
    Button1.Caption := '&Close';
    Form1.Caption := Edit1.Text;
    Exit;
  end;
  counter := StrToInt(Edit1.Text);
  Timer1.Enabled := True;
  Button1.Caption := '...';
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  if counter = 0 then
  begin
    Perform(WM_SYSCOMMAND, SC_MONITORPOWER, 1);
    Button1Click(Self);
  end
  else
  begin
    Dec(counter);
    Form1.Caption := IntToStr(counter) + 's left';
  end;
end;

procedure TForm1.HotKey1Change(Sender: TObject);
var
  tmp: char;
begin
  ShortCutToKey(HotKey1.HotKey, Key, ShiftState0);
  ShiftState := 0;
  if (ssShift in  ShiftState0) then
    ShiftState := ShiftState or MOD_SHIFT;
  if (ssCtrl in  ShiftState0) then
    ShiftState := ShiftState or MOD_CONTROL;
  if (ssAlt in  ShiftState0) then
    ShiftState := ShiftState or MOD_ALT;
  HotKeyId := GlobalAddAtom('MyHotKey') - $C000;
  RegisterHotKey(Handle, hotkeyid, ShiftState, Key);
end;

procedure TForm1.HotKeyDown(var Msg: Tmessage);
begin
  if (Msg.LparamLo = ShiftState) and (Msg.LParamHi = Key) then
  begin
    Button1Click(Self);
  end;
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  UnRegisterHotKey(handle, HotKeyId);
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -