請問一下如何攔截鍵盤P壓下及放開P鍵的訊息? |
尚未結案
|
nicolas
一般會員 發表:39 回覆:40 積分:15 註冊:2004-05-05 發送簡訊給我 |
|
allenchan
資深會員 發表:10 回覆:306 積分:283 註冊:2004-01-06 發送簡訊給我 |
LRESULT CALLBACK KeyboardProc( int code, // hook code
WPARAM wParam, // virtual-key code
LPARAM lParam // keystroke-message information
);
Parameters code Specifies a code the hook procedure uses to determine how to process the message. This parameter can be one of the following values: Value Meaning
HC_ACTION The wParam and lParam parameters contain information about a keystroke message.
HC_NOREMOVE The wParam and lParam parameters contain information about a keystroke message, and the keystroke message has not been removed from the message queue. (An application called the PeekMessage function, specifying the PM_NOREMOVE flag.)
If code is less than zero, the hook procedure must pass the message to the CallNextHookEx function without further processing and should return the value returned by CallNextHookEx. wParam Specifies the virtual-key code of the key that generated the keystroke message. lParam Specifies the repeat count, scan code, extended-key flag, context code, previous key-state flag, and transition-state flag. This parameter can be a combination of the following values: Value Description 0-15 Specifies the repeat count. The value is the number of times the keystroke is repeated as a result of the user's holding down the key. 16-23 Specifies the scan code. The value depends on the original equipment manufacturer (OEM). 24 Specifies whether the key is an extended key, such as a function key or a key on the numeric keypad. The value is 1 if the key is an extended key; otherwise, it is 0. 25-28 Reserved. 29 Specifies the context code. The value is 1 if the ALT key is down; otherwise, it is 0. 30 Specifies the previous key state. The value is 1 if the key is down before the message is sent; it is 0 if the key is up. 31 Specifies the transition state. The value is 0 if the key is being pressed and 1 if it is being released.
|
allenchan
資深會員 發表:10 回覆:306 積分:283 註冊:2004-01-06 發送簡訊給我 |
|
nicolas
一般會員 發表:39 回覆:40 積分:15 註冊:2004-05-05 發送簡訊給我 |
不行耶 怎麼辦
==================
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
procedure WMHotKey(var Msg : TMESSAGE); message WM_HOTKEY;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.WMHotKey (var Msg : TMESSAGE);
begin
ShowMessage(INTTOHEX(Msg.LParam,4));
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
RegisterHotKey(Handle,101,0,80);
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
UnRegisterHotKey (Handle,101);
end;
|
allenchan
資深會員 發表:10 回覆:306 積分:283 註冊:2004-01-06 發送簡訊給我 |
|
nicolas
一般會員 發表:39 回覆:40 積分:15 註冊:2004-05-05 發送簡訊給我 |
|
allenchan
資深會員 發表:10 回覆:306 積分:283 註冊:2004-01-06 發送簡訊給我 |
|
nicolas
一般會員 發表:39 回覆:40 積分:15 註冊:2004-05-05 發送簡訊給我 |
能給個範例嗎?謝謝
攔到的訊息如何傳到設定的程式呢? ===========
function KeyboardHookHandler(iCode: Integer;wParam: WPARAM;lParam: LPARAM): LRESULT; stdcall; export;
const _KeyPressMask = $40000000;
begin
Result := 0;
IF iCode < 0 THEN
BEGIN
Result := CallNextHookEx(hNextHookProc, iCode, wParam, lParam);
Exit;
END; IF wParam = Ord('P') THEN
BEGIN
Result := 1;
CASE lParam OF
WM_KEYDOWN: SHOWMESSAGE('WM_KEYDOWN');
WM_KEYUP : SHOWMESSAGE('WM_KEYUP');
END;
IF (_KeyPressMask AND lParam)>0 THEN
MessageBeep(0);
END;
END; function EnableHotKeyHook: BOOL; export;
begin
Result := False;
if hNextHookProc <> 0 then Exit; { 掛上 WH_KEYBOARD 這型的 HOOK, 同時, 傳回值必須保留下來, 免得 HOOK 呼叫鏈結斷掉}
hNextHookProc := SetWindowsHookEx(WH_KEYBOARD,KeyboardHookHandler,HInstance,0);
Result := hNextHookProc <> 0;
end; function DisableHotKeyHook: BOOL; export;
begin
if hNextHookProc <> 0 then
begin
UnhookWindowshookEx(hNextHookProc);
hNextHookProc := 0;
end;
Result := hNextHookProc = 0;
end; procedure HotKeyHookExit;
begin
if hNextHookProc <> 0 then DisableHotKeyHook;
ExitProc := procSaveExit;
end;
|
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |