![]() |
| ||
|
|
Новости |
Поиск |
FAQ |
Статьи |
Книги |
Новости VCL
| | Форумы ЧАТ |
Орешник |
|
| |||
| |||
« предыдущая ветвь | форум | следующая ветвь »
Как правильно обрабатывать сообщения от клаватуры?
fag2000@ok.ru © (2002-03-05 14:44:00)Скачал пример HOOK"а ( Большое спасибо авторам)( http://delphi.mastak.ru/cgi-bin/faq.pl?look=1&id=988619882&n=15) В принципе все работает только есть маленькая проблема: коды нажатия клавиш передаются не всегда верно(При любой раскладке и любом регистре идут коды больших латинских букв).
//код Hook"а
Function KeyboardHook(Code: Integer; ParamW: WPARAM; ParamL: LPARAM): LRESULT;stdcall;
Begin
If Code IN [HC_ACTION, HC_NOREMOVE] Then
Begin
SendMessage(ShareInf^.AppWndHandle, WM_USER, ParamW, Code);
End;
Result := CallNextHookEx(ShareInf^.OldHookHandle, Code, ParamW, ParamL)
End;
//Код обработчика
Procedure TMainForm.WMUser(var Message: TMessage);
Begin
Memo1.Lines.Add("Code: "+IntToStr(Message.WParam)+"; Char: "+Chr(Message.wParam));
End;
Raptor (2002-03-05 22:11:00) [1]Коды передаются верно, ведь то, что там выводится, это виртуальные коды клавиш а не конкретные символы. Получить символы не так просто, но тем не менее вся нужная для этого информация передается в хук в lParam.
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.
Имея эту информацию можно получить символы. Я сам лично этим не занимался, но советую посмотреть функцию ToAsciiEx().
Sasha9 (2002-03-05 18:10:00) [2]попробуй поставить хук WH_CALLWNDPROC или WH_CALLWNDPROCRET на отлов всех сообщений и обрабатывай только WM_KEYXXX
fag2000@ok.ru (2002-03-05 15:49:00) [3]Работает как раньше.:-(
Fellomena (2002-03-05 15:44:00) [4]Chr(Lo(Message.wParam))
(или Low - точно не помню 8)