안녕 하세요?
BacTeria 박종민 입니다.
키보드의 키를 가로 채려면 WM_HOTKEY 메시지를 이용하면 됩니다.
아래의 코드는 Enter 키를 '7'로 대체하는 코드입니다. 윈도우 전체에서...
VK_RETURN 대신에 다른 VK_... 키들을 넣어보세요.
이만... 박종민...
--------------------------------------------------------------------------------
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TMainForm = class(TForm)
Button1: TButton;
Memo1: TMemo;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
procedure WMHotKey(var Msg: TWMHotKey); message WM_HOTKEY;
public
{ Public declarations }
end;
var
MainForm: TMainForm;
implementation
{$R *.DFM}
procedure SimulateKeyDown(V_Key: Byte);
begin
Keybd_Event(V_Key, MapVirtualKey(V_Key, 0), 0, 0);
end;
procedure SimulateKeyUP(V_Key: Byte);
begin
Keybd_Event(V_Key, MapVirtualKey(V_Key, 0), KEYEVENTF_KEYUP, 0);
end;
procedure TMainForm.WMHotKey(var Msg: TWMHotKey);
begin
Case Msg.HotKey of
101: begin
SimulateKeyDown(Ord('7'));
SimulateKeyUp(Ord('7'));
end;
end;
end;
procedure TMainForm.FormCreate(Sender: TObject);
begin
RegisterHotKey(Handle, 101, 0, VK_RETURN);
end;
procedure TMainForm.FormDestroy(Sender: TObject);
begin
UnRegisterHotKey(Handle, 101);
end;
end.
|