?? unitmain.pas
字號:
unit UnitMain;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, XPMan, StdCtrls, ComCtrls;
type
TKeyAlterMainForm = class(TForm)
cb7toQ: TCheckBox;
cb1toZ: TCheckBox;
btnStart: TButton;
XPManifest1: TXPManifest;
sbBar: TStatusBar;
procedure FormCreate(Sender: TObject);
procedure btnStartClick(Sender: TObject);
procedure cb7toQClick(Sender: TObject);
procedure cb1toZClick(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
bIsHooOn: boolean;
procedure HookOn;
procedure HookOff;
procedure OnHotKey(var Message: TWMHotKey); message WM_HOTKEY;
public
{ Public declarations }
end;
const
WH_KEYBOARD_LL = 13;
var
hHook: Windows.HHOOK;
bIs7ToQ, bIs1ToZ: boolean;
type
tagKBDLLHOOKSTRUCT = packed record
vkCode: DWORD;
scanCode: DWORD;
flags: DWORD;
time: DWORD;
dwExtraInfo: DWORD;
end;
KBDLLHOOKSTRUCT = tagKBDLLHOOKSTRUCT;
PKBDLLHOOKSTRUCT = ^KBDLLHOOKSTRUCT;
var
KeyAlterMainForm: TKeyAlterMainForm;
implementation
{$R *.dfm}
procedure TKeyAlterMainForm.FormCreate(Sender: TObject);
begin
bIsHooOn := false;
bIs7ToQ := true;
bIs1ToZ := true;
hHook := 0;
RegisterHotKey(Handle, 1, 0, VK_F7);
end;
function KeyboardProc(nCode: integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall;
begin
if nCode = HC_ACTION then
begin
if bIs7ToQ and (PKBDLLHOOKSTRUCT(lParam)^.vkCode = Ord('Q')) then
begin
if wParam = WM_KEYDOWN then
keybd_event(VK_NUMPAD7, 0, 0, 0)
else if wParam = WM_KEYUP then
keybd_event(VK_NUMPAD7, 0, KEYEVENTF_KEYUP, 0);
result := 1;
exit;
end;
if bIs1ToZ and (PKBDLLHOOKSTRUCT(lParam)^.vkCode = Ord('Z')) then
begin
if wParam = WM_KEYDOWN then
keybd_event(VK_NUMPAD1, 0, 0, 0)
else if wParam = WM_KEYUP then
keybd_event(VK_NUMPAD1, 0, KEYEVENTF_KEYUP, 0);
result := 1;
exit;
end;
end;
result := CallNextHookEx(hHook, nCode, wParam, lParam);
end;
procedure TKeyAlterMainForm.btnStartClick(Sender: TObject);
begin
if bIsHooOn then
HookOff
else
HookOn;
bIsHooOn := not bIsHooOn;
end;
procedure TKeyAlterMainForm.cb7toQClick(Sender: TObject);
begin
bIs7ToQ := not bIs7ToQ;
end;
procedure TKeyAlterMainForm.cb1toZClick(Sender: TObject);
begin
bIs1ToZ := not bIs1ToZ;
end;
procedure TKeyAlterMainForm.HookOff;
begin
if hHook = 0 then exit;
UnHookWindowsHookEx(hHook);
hHook := 0;
btnStart.Caption := '開始HOOK';
sbBar.Panels[0].Text := 'HOOK已經停止...';
MessageBeep(MB_OK);
end;
procedure TKeyAlterMainForm.HookOn;
begin
if hHook <> 0 then exit;
try
hHook := SetWindowsHookEx(WH_KEYBOARD_LL, @KeyboardProc, hInstance, 0);
except
MessageBox(Handle, '啟動出錯', 'KeyAlter By Shilyx', MB_ICONERROR);
end;
btnStart.Caption := '停止HOOK';
sbBar.Panels[0].Text := 'HOOK已經開始...';
MessageBeep(MB_ICONINFORMATION);
end;
procedure TKeyAlterMainForm.OnHotKey(var Message: TWMHotKey);
begin
if Message.HotKey = 1 then
btnStart.Click;
end;
procedure TKeyAlterMainForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
UnregisterHotKey(Handle, 1);
HookOff;
end;
end.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -