以下是一个按键地勾子:<br>Intercepting The TAB and ENTER Keys<br><br>{the prototype for the new keyboard hook function}<br> function KeyboardHook(nCode: Integer; wParam: WPARAM;<br> lParam: LPARAM): LResult; stdcall;<br><br>var<br> Form1: TForm1;<br> WinHook: HHOOK; // a handle to the keyboard hook function<br><br>implementation<br><br>{$R *.DFM}<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>begin<br><br> {install the keyboard hook function into the keyboard hook chain}<br> WinHook:=SetWindowsHookEx(WH_KEYBOARD, @KeyboardHook, 0, GetCurrentThreadID);<br>end;<br><br>procedure TForm1.FormDestroy(Sender: TObject);<br>begin<br> {remove the keyboard hook function from the keyboard hook chain}<br> UnhookWindowsHookEx(WinHook);<br>end;<br><br>function KeyboardHook(nCode: Integer; wParam: WPARAM; lParam: LPARAM): LResult;<br><br>begin<br> {if we can process the hook information...}<br> if (nCode>-1) then<br> {...was the TAB key pressed?}<br> if (wParam=VK_TAB) then<br> begin<br> {if so, output a beep sound}<br> MessageBeep(0);<br><br> {indicate that the message was processed}<br> Result := 1;<br> end<br> else<br> {...was the RETURN key pressed?}<br><br> if (wParam=VK_RETURN) then<br> begin<br> {if so, and if the key is on the up stroke, cause<br> the focus to move to the next control}<br> if ((lParam shr 31)=1) then<br> Form1.Perform(WM_NEXTDLGCTL, 0, 0);<br><br> {indicate that the message was processed}<br> Result := 1;<br> end<br> else<br> {otherwise, indicate that the message was not processed.}<br><br> Result := 0<br> else<br> {we must pass the hook information to the next hook in the chain}<br> Result := CallNextHookEx(WinHook, nCode, wParam, lParam);<br>end;<br>