Главная страница
    Top.Mail.Ru    Яндекс.Метрика
Форум: "Основная";
Текущий архив: 2006.09.24;
Скачать: [xml.tar.bz2];

Вниз

Вопрос по поводу Hook-a   Найти похожие ветки 

 
FireMan_Alexey ©   (2006-08-14 00:49) [0]

Когда устанавливаю хук на клаву с кодом 13 (только для 2000/ХР) не могу получить код нажатой клавиши? :(
Делаю так:
function KeyboardProc(code : integer; wParam : word; lParam : longint) : longint; stdcall;
begin
  ...
   SendMessage(GlobalData^.MyAppWnd, WM_MYHOOK, wParam, lParam);
  ...
end;

procedure hook(switch : Boolean; hMainProg: HWND) export; stdcall;
begin
 if switch=true then
 begin
     GlobalData^.SysHook := SetWindowsHookEx(13{Keyboard},@KeyboardProc, HInstance, 0);
   GlobalData^.MyAppWnd:= hMainProg;
  ...
end;


Получаю одинаковые коды со всех клавиш!
Может кто сталкивался с такой проблемой?


 
Zeqfreed ©   (2006-08-14 00:56) [1]

> [0] FireMan_Alexey ©   (14.08.06 00:49)

А как обрабатываешь wParam и lParam?


 
Ketmar ©   (2006-08-14 01:43) [2]

> [0] FireMan_Alexey ©   (14.08.06 00:49)
а кто это тебе наврал, что можно ставить хук на отдельную клавшу? читай MSDN, там много интересного написано.


 
Zeqfreed ©   (2006-08-14 02:04) [3]

> [2] Ketmar ©   (14.08.06 01:43)

«Когда устанавливаю хук на клаву с кодом 13» означает «Когда устанавливаю низкоуровневый клавиатурный хук (WH_KEYBOARD_LL)». ;)
Ни слова про отдельные клавиши.


 
Ketmar ©   (2006-08-14 02:17) [4]

> [3] Zeqfreed ©   (14.08.06 02:04)
так вот что, константы запретили указом президента? равно как и внятное формулирование вопросов?

а вообще -- ошибка в 17-й строке. присоединяюсь к [1].


 
FireMan_Alexey ©   (2006-08-14 03:09) [5]

>Ketmar ©
обрабатываю? :/
Процедура хука, возвращает одни и те же значения в не зависимости от размера переменной! А откуда еще можно взять код нажатой/отжатой клавиши?
WH_KEYBOARD_LL - описанной в Делфи 6 нет!во всяком случае в модуле windows! Т.о. появилась константа!


 
FireMan_Alexey ©   (2006-08-14 03:27) [6]

>Zeqfreed
Т.е. Ты хочеш сказать, что низкоуровневый хук не возвращает код нажатой/отжатой клавиши?


 
FireMan_Alexey ©   (2006-08-14 03:36) [7]

Из процедуры обработчика хука
function KeyboardProc(code : integer; wParam : word; lParam : longint) : longint; stdcall;
begin
 ...
  SendMessage(GlobalData^.MyAppWnd, WM_MYHOOK, wParam, lParam);
 ...
end;


А в программе получаю сообщение и вывожу значения на экран!
в wParam значения принимаю принажатии 256 и 257 при отжатии lParam всегда 1244872. :/
Вот и спрашиваю как узнать код нажатой клавиши?


 
Шпиён   (2006-08-14 04:07) [8]


> Вот и спрашиваю как узнать код нажатой клавиши?



WH_KEYBOARD_LL=13;
type
 pKBDLLHOOKSTRUCT=^TKBDLLHOOKSTRUCT;
 TKBDLLHOOKSTRUCT=record
   vkCode:DWORD;
   scanCode:DWORD;
   flags:DWORD;
   time:DWORD;
   dwExtraInfo:pDWORD;
 end;
var
 MyHook:HHOOK;
 p:pKBDLLHOOKSTRUCT;
  SL:TStringList;

function LowLevelKeyboardProc(nCode:integer;wParam:longint;lParam:longint):longint;stdcal l;
begin
................................
   if (wParam=WM_KEYUP) or (wParam=WM_KEYDOWN) then
       begin
           p:=pKBDLLHOOKSTRUCT(lparam);
           SL.Add(IntToHex(p.vkCode,2)+" ");
       end;
.............................
end;


 
Шпиён   (2006-08-14 04:12) [9]

MSDN
Syntax

LRESULT CALLBACK LowLevelKeyboardProc(          int nCode,
   WPARAM wParam,
   LPARAM lParam
);
Parameters

nCode
[in] Specifies a code the hook procedure uses to determine how to process the message. If nCode 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. This parameter can be one of the following values.
HC_ACTION
The wParam and lParam parameters contain information about a keyboard message.
wParam
[in] Specifies the identifier of the keyboard message. This parameter can be one of the following messages: WM_KEYDOWN, WM_KEYUP, WM_SYSKEYDOWN, or WM_SYSKEYUP.
lParam
[in] Pointer to a KBDLLHOOKSTRUCT structure.

KBDLLHOOKSTRUCT Structure

--------------------------------------------------------------------------------

The KBDLLHOOKSTRUCT structure contains information about a low-level keyboard input event.

Syntax

typedef struct {
   DWORD vkCode;
   DWORD scanCode;
   DWORD flags;
   DWORD time;
   ULONG_PTR dwExtraInfo;
} KBDLLHOOKSTRUCT, *PKBDLLHOOKSTRUCT;
Members

vkCode
Specifies a virtual-key code. The code must be a value in the range 1 to 254.
scanCode
Specifies a hardware scan code for the key.
flags
Specifies the extended-key flag, event-injected flag, context code, and transition-state flag. This member is specified as follows. An application can use the following values to test the keystroke flags. Value Purpose
LLKHF_EXTENDED Test the extended-key flag.  
LLKHF_INJECTED Test the event-injected flag.  
LLKHF_ALTDOWN Test the context code.  
LLKHF_UP Test the transition-state flag.  

0
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.
1-3
Reserved.
4
Specifies whether the event was injected. The value is 1 if the event was injected; otherwise, it is 0.
5
Specifies the context code. The value is 1 if the ALT key is pressed; otherwise, it is 0.
6
Reserved.
7
Specifies the transition state. The value is 0 if the key is pressed and 1 if it is being released.
time
Specifies the time stamp for this message, equivalent to what GetMessageTime would return for this message.
dwExtraInfo
Specifies extra information associated with the message.


 
FireMan_Alexey ©   (2006-08-14 09:00) [10]

>Шпиён
Огромное спасибо! :)
Все работает!



Страницы: 1 вся ветка

Форум: "Основная";
Текущий архив: 2006.09.24;
Скачать: [xml.tar.bz2];

Наверх





Память: 0.48 MB
Время: 0.042 c
15-1157317488
ramzes2
2006-09-04 01:04
2006.09.24
как назначить родителя диалогу


1-1155652862
sdf13
2006-08-15 18:41
2006.09.24
немецкий текст.


15-1157433847
Ega23
2006-09-05 09:24
2006.09.24
С Днём рождения! 5 сентября


4-1148457913
truegosha
2006-05-24 12:05
2006.09.24
QueryServiceStatus Отказано в доступе


1-1155199317
apl
2006-08-10 12:41
2006.09.24
Можно ли?





Afrikaans Albanian Arabic Armenian Azerbaijani Basque Belarusian Bulgarian Catalan Chinese (Simplified) Chinese (Traditional) Croatian Czech Danish Dutch English Estonian Filipino Finnish French
Galician Georgian German Greek Haitian Creole Hebrew Hindi Hungarian Icelandic Indonesian Irish Italian Japanese Korean Latvian Lithuanian Macedonian Malay Maltese Norwegian
Persian Polish Portuguese Romanian Russian Serbian Slovak Slovenian Spanish Swahili Swedish Thai Turkish Ukrainian Urdu Vietnamese Welsh Yiddish Bengali Bosnian
Cebuano Esperanto Gujarati Hausa Hmong Igbo Javanese Kannada Khmer Lao Latin Maori Marathi Mongolian Nepali Punjabi Somali Tamil Telugu Yoruba
Zulu
Английский Французский Немецкий Итальянский Португальский Русский Испанский