線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:2123
推到 Plurk!
推到 Facebook!

請問一下如何攔截鍵盤P壓下及放開P鍵的訊息?

尚未結案
nicolas
一般會員


發表:39
回覆:40
積分:15
註冊:2004-05-05

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-12-01 18:06:08 IP:61.219.xxx.xxx 未訂閱
請問一下如何攔截鍵盤P壓下(keydown)及放開(keyUP)P鍵的訊息? 用HOOK好像只能截鍵盤P(KEYPRESS) 謝謝
allenchan
資深會員


發表:10
回覆:306
積分:283
註冊:2004-01-06

發送簡訊給我
#2 引用回覆 回覆 發表時間:2004-12-01 18:52:56 IP:203.70.xxx.xxx 未訂閱
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

發送簡訊給我
#3 引用回覆 回覆 發表時間:2004-12-01 21:09:56 IP:61.62.xxx.xxx 未訂閱
就是判斷 lParam 0~31 bit 中,第 30 bit 是 0 or 1,可以拿 lParam & 0x40000000 就知道是 Down or Up 了。
nicolas
一般會員


發表:39
回覆:40
積分:15
註冊:2004-05-05

發送簡訊給我
#4 引用回覆 回覆 發表時間:2004-12-02 16:41:15 IP:61.219.xxx.xxx 未訂閱
不行耶 怎麼辦 ================== 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

發送簡訊給我
#5 引用回覆 回覆 發表時間:2004-12-02 17:11:47 IP:61.230.xxx.xxx 未訂閱
你這不是 windows Keyboard hook 的程式咧 ~~ 
nicolas
一般會員


發表:39
回覆:40
積分:15
註冊:2004-05-05

發送簡訊給我
#6 引用回覆 回覆 發表時間:2004-12-02 20:58:14 IP:220.139.xxx.xxx 未訂閱
引言: 你這不是 windows Keyboard hook 的程式咧 ~~ < face="Verdana, Arial, Helvetica"> 哪怎麼半呢
allenchan
資深會員


發表:10
回覆:306
積分:283
註冊:2004-01-06

發送簡訊給我
#7 引用回覆 回覆 發表時間:2004-12-02 21:02:53 IP:61.62.xxx.xxx 未訂閱
參考一下: http://delphi.ktop.com.tw/topic.php?topic_id=19936 http://delphi.ktop.com.tw/topic.php?topic_id=47170 或是搜尋一下 hook 字眼。
nicolas
一般會員


發表:39
回覆:40
積分:15
註冊:2004-05-05

發送簡訊給我
#8 引用回覆 回覆 發表時間:2004-12-08 14:46:05 IP:61.219.xxx.xxx 未訂閱
能給個範例嗎?謝謝 攔到的訊息如何傳到設定的程式呢? =========== 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;
系統時間:2024-04-26 16:57:14
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!