// ½ÇÇà¹æ¹ý:
// ÇÁ·Î±×·¥À» ÄÄÆÄÀÏÇÏ¿© ½ÇÇàÇϸé ÇÁ·Î±×·¥Àº minimized µÇ°í
// ¸Þ¸ðÀåÀÌ Çϳª ¶ß´Âµ¥ ¸Þ¸ðÀå ¾È¿¡¼ F8 ¶Ç´Â F9 ۸¦ ´·¯º¸¼¼¿ä
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs, ShellAPI;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormActivate(Sender: TObject);
private
{ Private declarations }
procedure WMHotkey(var msg: TWMHotkey); message WM_HOTKEY;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure PostKeyEx32(key: Word; const shift: TShiftState;
specialkey: Boolean);
type
TShiftKeyInfo = record
shift: Byte;
vkey : Byte;
end;
ByteSet = set of 0..7;
const
shiftkeys: array [1..3] of TShiftKeyInfo =
((shift: Ord(ssCtrl); vkey: VK_CONTROL),
(shift: Ord(ssShift); vkey: VK_SHIFT),
(shift: Ord(ssAlt); vkey: VK_MENU));
var
flag: DWORD;
bShift: ByteSet absolute shift;
i: Integer;
begin
// VirtualKey key down ¹ß»ý
for i := 1 to 3 do
begin
if shiftkeys[i].shift in bShift then
keybd_event(shiftkeys[i].vkey,
MapVirtualKey(shiftkeys[i].vkey, 0),
0, 0);
end;
if specialkey then
flag := KEYEVENTF_EXTENDEDKEY
else
flag := 0;
// ÀϹݹ®ÀÚ key down ¹ß»ý
keybd_event(key, MapvirtualKey(key, 0), flag, 0);
flag := flag or KEYEVENTF_KEYUP;
// ÀϹݹ®ÀÚ key up ¹ß»ý
keybd_event(key, MapvirtualKey(key, 0), flag, 0);
// VirtualKey key up ¹ß»ý
for i := 3 downto 1 do
begin
if shiftkeys[i].shift in bShift then
keybd_event(shiftkeys[i].vkey,
MapVirtualKey(shiftkeys[i].vkey, 0),
KEYEVENTF_KEYUP, 0);
end;
end;
procedure SendText(S: String);
var
flags: TShiftState;
vcode: word;
ret : word;
i, n : Integer;
mask : word;
begin
for i := 1 to Length(S) do
begin
ret := VkKeyScan(S[i]);
vcode := Lobyte(ret);
flags := [];
mask := $100;
for n := 1 to 3 do
begin
if (ret and mask) <> 0 then
begin
case mask of
$100: Include(flags, ssShift);
$200: Include(flags, ssCtrl);
$400: Include(flags, ssAlt);
end;
end;
mask := mask shl 1;
end;
PostKeyEx32(vcode, Flags, False);
end;
end;
procedure TForm1.WMHotkey(var msg: TWMHotkey);
begin
case msg.HotKey of
1: SendText('hello'); // F8
2: SendText('world'); // F9
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
// ÀÌ ÇÁ·Î±×·¥ÀÌ WM_HOTKEY ¸Þ½ÃÁö¸¦ ¹ÞÀ» ¼ö ÀÖµµ·Ï µî·ÏÇÑ´Ù
if not RegisterHotkey(Handle, 1, 0, VK_F8) then
ShowMessage('F8À» hotkey·Î ÇÒ´çÇÒ ¼ö ¾ø½À´Ï´Ù');
if not RegisterHotkey(Handle, 2, 0, VK_F9) then
ShowMessage('F9¸¦ hotkey·Î ÇÒ´çÇÒ ¼ö ¾ø½À´Ï´Ù');
WinExec('notepad', SW_SHOWNORMAL); // Å×½ºÆ®¿ë ÇÁ·Î±×·¥
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
// µî·ÏµÈ Hotkey ¸¦ ÇØÁ¦ÇÑ´Ù
UnRegisterHotkey(Handle, 1);
UnRegisterHotkey(Handle, 2);
end;
procedure TForm1.FormActivate(Sender: TObject);
begin
ShowWindow(Handle, SW_MINIMIZE);
end;
end. |
|