нашел тему где то на винграде и заделал под себя, но проблема в том что как только зажимаю ctrl+mouse1, то бесконечно много вылезает мессаг, мне надо чтобы одно нажатие, означало один вызов моего условия, помогите плз:
| Код | library HookDLL;
uses SysUtils, Classes, Windows, Messages, dialogs;
const WM_SETFORE = WM_USER + 101;
var HKbdHook: HHook; MForm: HWND;
{$R *.res}
//------------------------------------------------------------------------------ // Hook //------------------------------------------------------------------------------ function KeyboardProc(nCode: Integer; WP: wParam; LP: lParam): integer; stdcall; begin Result := CallNextHookEx(HKbdHook, nCode, WP, LP); if nCode = HC_ACTION then begin //if (WP = 46) and (HI(GetKeyState(VK_CONTROL)) = 255) and (HI(GetKeyState(VK_MENU)) = 255) then if (HI(GetKeyState(VK_CONTROL)) = 255) and (HI(GetKeyState(VK_LBUTTON)) = 255) then begin ShowMessage('GGG'); // SetforeGroundWindow(MFOrm); //SendMessage(MForm, WM_SETFORE, 0, 0); end; end; end;
//------------------------------------------------------------------------------
procedure Hook(Flag: boolean; Handl: HWND); export; stdcall; Begin MForm := Handl; if Flag then HKbdHook := SetWindowsHookEx(WH_KEYBOARD, @KeyboardProc, HInstance, 0) else begin UnhookWindowsHookEx(HKbdHook); HKbdHook := 0; end; end;
exports Hook;
begin end.
|
| Код | interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, AppEvnts;
const WM_SETFORE = WM_USER + 101;
type TKeyboardProc = procedure (Flag: boolean; Handl: HWND); stdcall; TForm1 = class(TForm) procedure FormCreate(Sender: TObject); procedure FormDestroy(Sender: TObject); private { Private declarations } public { Public declarations } protected procedure HotKeyReleased(var Message: TWmHotKey); message WM_HOTKEY; procedure WMSETFORE(var Message: TMsg); message WM_SETFORE; end;
var Form1: TForm1; HKey: integer; HKbdHook: integer; HookProc: TKeyboardProc; HookDLL: HModule; UniqKey: string; MsgId: integer; implementation
{$R *.dfm} //------------------------------------------------------------------------------ { * * * * * * * * * * * * * * * * TfrmMain * * * * * * * * * * * * * * * * * * } //------------------------------------------------------------------------------ // Îáðàáîò÷èê ãîðÿ÷åé êëàâèøè //------------------------------------------------------------------------------ procedure Tform1.HotKeyReleased(var Message: TWmHotKey); begin if Message.HotKey = HKey then begin SetForeGroundWindow(Handle); ShowMessage('Alt+Tab pressed!'); end; end;
//------------------------------------------------------------------------------
procedure Tform1.WMSETFORE(var Message: TMsg); begin SetForeGroundWindow(Handle); ShowMessage('Ctrl+Alt+Del pressed!'); end;
//------------------------------------------------------------------------------
procedure Tform1.FormCreate(Sender: TObject); begin HKey := GlobalAddAtom('MyHotKey'); RegisterHotKey(Handle, HKey, MOD_ALT, 9); HookDLL := LoadLibrary('HookDLL.dll'); @HookProc := getProcAddress(HookDLL, 'Hook'); HookProc(True, Handle); end;
//------------------------------------------------------------------------------
procedure TForm1.FormDestroy(Sender: TObject); begin UnRegisterHotKey(Handle, HKey); HookProc(False, Handle); FreeLibrary(HOOKDLL); end;
|
|